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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
SanderTK
Frequent Visitor

Editing behaviour of (sub)totals using DAX

I am using a very simple measure that is an IF statement to determine values based on other values.

If more than 500 tickets are sold I want the value 100 returned, else if more than 400 are sold I want the value 50 else I want the value 25.

Calculating the amount of tickets sold is a stand-alone measure so the IF statement looks a bit like this:

My Measure =
IF([num tickets sold] > 500, 100,(IF[num tickets sold] > 400,50,25))

I format this in a matrix on the granularity of days.

This works perfect on days with 1 event but as soon as there are 2 events on 1 day, it gives me the sum of tickets sold of those two events (lets say 200 and 300) which would be 500, giving me a result of 100 when in fact the result should be 25+25 = 50.

example.png
(example made in Excel because it was a faster way of visualizing the issue)

I can solve this by going one level deeper and placing the events underneath the dates so that I can drill down one step further and get the right results on event level but what I cannot seem to do is get the totals right.

Because of the filter context in the totals I have the same problem as with days with multiple events but all I know what to do about this, is to hide the totals by using a IF(HASONEVALUE) statement on the day column.

What I would like to do basically is get the actual totals of the previous rows and sum them in the (sub)total field.

2 ACCEPTED SOLUTIONS
bsheffer
Continued Contributor
Continued Contributor

would sumx(event_table, mymeasure) help?

 

View solution in original post

v-rzhou-msft
Community Support
Community Support

Hi @SanderTK ,

 

Here I create a sample to have a test.

RicoZhou_0-1678170277157.png

Measure:

Measure = 
VAR _SUMMAZIRE =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Date],
            'Table'[Event],
            "num tickets sold", CALCULATE ( SUM ( 'Table'[num tickets sold] ) )
        ),
        "IF",
            IF ( [num tickets sold] > 500, 100, IF ( [num tickets sold] > 400, 50, 25 ) )
    )
RETURN
    SUMX ( _SUMMAZIRE, [IF] )

Result is as below.

RicoZhou_1-1678170299424.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
v-rzhou-msft
Community Support
Community Support

Hi @SanderTK ,

 

Here I create a sample to have a test.

RicoZhou_0-1678170277157.png

Measure:

Measure = 
VAR _SUMMAZIRE =
    ADDCOLUMNS (
        SUMMARIZE (
            'Table',
            'Table'[Date],
            'Table'[Event],
            "num tickets sold", CALCULATE ( SUM ( 'Table'[num tickets sold] ) )
        ),
        "IF",
            IF ( [num tickets sold] > 500, 100, IF ( [num tickets sold] > 400, 50, 25 ) )
    )
RETURN
    SUMX ( _SUMMAZIRE, [IF] )

Result is as below.

RicoZhou_1-1678170299424.png

 

Best Regards,
Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

What I was missing was adding the tickets sold from the transactions table to the events table which I can do with the last argument of that SUMMARIZE statement. It works perfectly now, thank you so much for the help!

bsheffer
Continued Contributor
Continued Contributor

would sumx(event_table, mymeasure) help?

 

I now realize that I was using the SUMX over the transactions table (which I would need to calculate the sum of tickets sold). If I had the amount of tickets sold in the events table this would've worked perfectly. Thank you for the help!

I have tried this but with no result. Tried using keep/removefilters as well but did not help.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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