Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
as1195
Helper I
Helper I

need help with DAX optimisation

Hi,

I am trying to find top competitor using below measure.Whenever I am using this measure in the report this is hitting performance very badly.how should I optimise the  below measure?Will creating the virtual table "Manuf"  in the data source helps?

Top Retailer =
VAR Time =
    SELECTEDVALUE ( 'Time'[TimeCalculation] )
VAR Manuf =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( ALLSELECTED ( 'Manufacturer' ), [Manufacturer] ),
            "TotalValue",
                CALCULATE (
                    SUM ( 'Sales'[Value] ),
                    ALL ( 'Time' ),
                    'Time'[Offset] = 0,
                    'Time[TimeCalculation] = TimeCalculation,
                    ALL ( Brand )
                )
        ),
        AND (
            NOT ( [Manufacturer] ) IN { "abc","xyz"},
            NOT ( ISBLANK ( [TotalValue] ) )
        )
    )
VAR Top1 =
    TOPN ( 1, Manuf, [TotalValue], DESC )
RETURN
    MAXX ( Top1, [Manufacturer] )

3 REPLIES 3
FreemanZ
Super User
Super User

In a post like this and in most cases, the requirement/expectation and sample data are more important than any line of code.

amitchandak
Super User
Super User

@as1195 ,The information you have provided is not making the problem clear to me. Can you please explain with an example.

Can you share sample data and sample output in table format? Or a sample pbix after removing sensitive data.
Appreciate your Kudos.

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Hi Amit,

Unfortunaletly I am not able to attach sample file here.Please find the snippet for the same.
Manufacturer table holds unique manufacturer.

as1195_3-1671516438482.png
Manufacture pivot table has Top Competitor defined for each of the manufacturer along with inidvidual manufacturer.

as1195_0-1671516306903.png


Sales table holds sales and other details.

as1195_1-1671516329618.png


Time table holds Latest12Weeks and Latest4week data.

as1195_2-1671516360454.png


What I am trying to find is the Top Retailer .For ex
For Egypt & Vegetables, when Top Competitor is selected from slicer the query should hit all the Egypt and Vegetables combination from sales tables and give the highest sales manufacturer as a result.

as1195_7-1671516970061.png

 

When user selects any other manufacturer other than Top Competitor,the sales values should show against the selected manufacturer

as1195_5-1671516800197.png
Top Retailer Measure=

Top Retailer =
var timevalue=SELECTEDVALUE('Time'[Time])
VAR Manuf1 =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( ALLSELECTED ( 'Manufacturer' ), [Manufacturer] ),
            "TotalValue",
                CALCULATE (
                    SUM ( 'Sales'[Sales Value] ),
                    all('Time'),
                    'Time'[Time]=TIMEVALUE
                )
        ),
        AND (
            NOT ( [Manufacturer] ) IN {"Others" },
            NOT ( ISBLANK ( [TotalValue] ) )
        )
    )
VAR Top1 =
    TOPN ( 1, Manuf1, [TotalValue], DESC )
RETURN
    MAXX ( Top1, [Manufacturer] )

Is there any way I can achieve the same result without creating a table inside the measure?

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

Check out the July 2025 Power BI update to learn about new features.

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.