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
WTsrnl
Frequent Visitor

using DAX to calc the sum, whilst excluding the first registered amount of liters

Hi all,

I need a bit of help. I couldn't find any other threads that could help me with this, and if you do, i'd love to know about it.

 

I need to build a DAX measure that calculates the average amount of liters used / person / km. But whilst calculating this, I need to exclude the amount of liters used on the first date.

 

I tried to find the first date per person, and exclude the liters registered from the sum of total liters per person. After that i can calculate the average km/liter. I just can't find the way to find the first date per person.

 

If you have any questions, please let me know.

 

LitersDatePersonkm driven
3318-3-2022A55800
362-4-2022A56204
2515-4-2022A56670
304-5-2022A57075
2414-5-2022A57515
3026-5-2022A57962
288-6-2022A58483
2025-6-2022A58914
4019-3-2022B35000
343-4-2022B35523
3323-4-2022B36050
294-5-2022B36484
2121-5-2022B36960
354-6-2022B37445
2223-6-2022B37980
275-7-2022B38486
3520-3-2022C28000
334-4-2022C28545
2216-4-2022C28969
3126-4-2022C29426
2312-5-2022C29881
2028-5-2022C30385
217-6-2022C30926
2127-6-2022C31358
375-4-2022D33560
2615-4-2022D34002
2825-4-2022D34462
3215-5-2022D34868
274-6-2022D35292
3016-6-2022D35789
354-7-2022D36200
286-4-2022E34500
2524-4-2022E34966
2014-5-2022E35463
2528-5-2022E35876
2815-6-2022E36288
2028-6-2022E36741
2110-7-2022E37203
1 ACCEPTED SOLUTION
v-rzhou-msft
Community Support
Community Support

Hi @WTsrnl ,

 

I think you can try this code to calculate total liters exculde first date per person.

Total Exclude First Date =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Person],
        "Liters exclude first date",
            VAR _First_Date =
                CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Person] ) )
            RETURN
                CALCULATE (
                    SUM ( 'Table'[Liters] ),
                    FILTER ( ALLEXCEPT ( 'Table', 'Table'[Person] ), 'Table'[Date] > _First_Date )
                )
    )
RETURN
    SUMX ( _SUMMARIZE, [Liters exclude first date] )

Result is as below.

RicoZhou_1-1656409386142.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

2 REPLIES 2
v-rzhou-msft
Community Support
Community Support

Hi @WTsrnl ,

 

I think you can try this code to calculate total liters exculde first date per person.

Total Exclude First Date =
VAR _SUMMARIZE =
    SUMMARIZE (
        'Table',
        'Table'[Person],
        "Liters exclude first date",
            VAR _First_Date =
                CALCULATE ( MIN ( 'Table'[Date] ), ALLEXCEPT ( 'Table', 'Table'[Person] ) )
            RETURN
                CALCULATE (
                    SUM ( 'Table'[Liters] ),
                    FILTER ( ALLEXCEPT ( 'Table', 'Table'[Person] ), 'Table'[Date] > _First_Date )
                )
    )
RETURN
    SUMX ( _SUMMARIZE, [Liters exclude first date] )

Result is as below.

RicoZhou_1-1656409386142.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.

 

Works! Thanks, the summarize function was unknown to me, but very handy to group certain tables within a measure. 

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.