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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
as1195
Frequent Visitor

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.

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
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

Top Solution Authors