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
hcze
Helper I
Helper I

Total YTD on various levels

 

Hi,

I need some helps to calculate total YTD using DAX with some conditions:

- No date table. It works with TOTALYTD function but it is not what I am looking for.

- The formula should take care of filters in the query as well as from outside (e.g. slicer).

 

Expected output looks similar to the following screenshots

 

1.jpg2.jpg3.jpg

 

Sample data as follow:

CompanyCategoryCustomerProductYearQuarterValue
AAACat1AmazonProd12018110
AAACat1AmazonProd1201812
AAACat1AmazonProd32018112
AAACat1AmazonProd12018223
AAACat1AmazonProd12018224
AAACat1AmazonProd32018212
AAACat1AmazonProd1201834
AAACat1AmazonProd22018345
AAACat1AmazonProd3201835
AAACat1AmazonProd3201843
AAACat1GoogleProd12018123
AAACat1GoogleProd32018137
AAACat1GoogleProd32018126
AAACat1GoogleProd12018212
AAACat1GoogleProd22018234
AAACat1GoogleProd22018278
AAACat1GoogleProd12018334
AAACat1GoogleProd12018360
AAACat1GoogleProd32018310
AAACat1GoogleProd12018434
AAACat2AmazonProd12019167
AAACat2AmazonProd12019113
AAACat2AmazonProd32019112
AAACat2AmazonProd12019218
AAACat2AmazonProd12019218
AAACat2AmazonProd3201922
AAACat2AmazonProd12019323
AAACat2AmazonProd22019341
AAACat2AmazonProd32019345
AAACat2AmazonProd32019437
AAACat2GoogleProd12019140
AAACat2GoogleProd3201918
AAACat2GoogleProd32019155
AAACat2GoogleProd12019248
AAACat2GoogleProd22019223
AAACat2GoogleProd22019218
AAACat2GoogleProd12019310
AAACat2GoogleProd12019343
AAACat2GoogleProd3201939
AAACat2GoogleProd12019475
BBBCat1AmazonProd1201816
BBBCat1AmazonProd12018145
BBBCat1AmazonProd32018136
BBBCat1AmazonProd1201829
BBBCat1AmazonProd12018267
BBBCat1AmazonProd32018221
BBBCat1AmazonProd12018315
BBBCat1AmazonProd22018338
BBBCat1AmazonProd32018326
BBBCat1AmazonProd32018424
BBBCat1GoogleProd12018135
BBBCat1GoogleProd32018114
BBBCat1GoogleProd32018137
BBBCat1GoogleProd12018236
BBBCat1GoogleProd22018224
BBBCat1GoogleProd22018219
BBBCat1GoogleProd12018321
BBBCat1GoogleProd12018328
BBBCat1GoogleProd32018343
BBBCat1GoogleProd12018427
BBBCat2AmazonProd12019116
BBBCat2AmazonProd12019136
BBBCat2AmazonProd32019118
BBBCat2AmazonProd12019223
BBBCat2AmazonProd12019227
BBBCat2AmazonProd32019231
BBBCat2AmazonProd12019340
BBBCat2AmazonProd22019315
BBBCat2AmazonProd32019321
BBBCat2AmazonProd32019434
BBBCat2GoogleProd12019110
BBBCat2GoogleProd32019121
BBBCat2GoogleProd32019134
BBBCat2GoogleProd12019216
BBBCat2GoogleProd22019211
BBBCat2GoogleProd22019210
BBBCat2GoogleProd1201934
BBBCat2GoogleProd12019323
BBBCat2GoogleProd32019335
BBBCat2GoogleProd12019424

 

 

Thank you,

Lin

1 ACCEPTED SOLUTION
dax
Community Support
Community Support

Hi hcze, 

This should work, it is based on Quarter to calculate running total, so when [Quarter] field in Table or Matrix, it should calculate running total correctly. In addition, in your image, I saw you don't want to calculate running total when [Category] in visual, so I use if condition in measure. You could refer to my sample.

Best Regards,
Zoe Zhi

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

6 REPLIES 6
dax
Community Support
Community Support

Hi hcze, 

According to your description, it seems that when the Category in Matrix, you don't want to show running total in it, right? If so, you could try to use below measure to see whether it work or not.

Measure 2 = if(ISINSCOPE('Table'[Category]),Sum('Table'[Value]),
VAR SelectedQuarter =
    MAX ( 'Table'[Quarter] )
RETURN
    CALCULATE (
        Sum('Table'[Value]),
        FILTER ( ALL ( 'Table'[Quarter] ), 'Table'[Quarter] <= SelectedQuarter )
    ))

Best Regards,
Zoe Zhi

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

Thanks, @dax Zoe. I would prefer to make the DAX more flexible, meaning I could drop other dimensions (e.g. Product or Customer) and still get the correct running total.

Also FILTER ALL removes all filters and it is not the number I want.

dax
Community Support
Community Support

Hi hcze, 

This should work, it is based on Quarter to calculate running total, so when [Quarter] field in Table or Matrix, it should calculate running total correctly. In addition, in your image, I saw you don't want to calculate running total when [Category] in visual, so I use if condition in measure. You could refer to my sample.

Best Regards,
Zoe Zhi

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

That's perfect. Thanks Zoe and Happy New Year!

@dax 

Tahreem24
Super User
Super User

@hcze ,

 

Give a try using below query.

YTD Measure =
VAR SelectedQuarter =
    MAX ( Table[Quarter] )
RETURN
    CALCULATE (
        Sum(Table[TotalColumn]),
        FILTER ( ALL ( Table[Quarter] ), Table[Quarter] <= SelectedQuarter )
    )

Don't forget to hit THUMBS UP and mark it as a solution if it helps you!

Don't forget to give thumbs up and accept this as a solution if it helped you!!!

Please take a quick glance at newly created dashboards : Restaurant Management Dashboard , HR Analytics Report , Hotel Management Report, Sales Analysis Report , Fortune 500 Companies Analysis , Revenue Tracking Dashboard

Thanks Tahreem but the FILTER ALL removes all filters from inside and outside the matrix but I want the opposite.

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.