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
smpa01
Super User
Super User

DAX to display Current period, Yearly total and YTD Running total

Hello Experts,

 

My source data is following

 

NameCATQuarterAmount
Name1CAT111000
Name1CAT122000
Name1CAT133000
Name1CAT144000
Name1CAT21100
Name1CAT22200
Name1CAT23300
Name1CAT24400
Name2CAT1110000
Name2CAT1210000
Name2CAT1310000
Name2CAT1410000
Name2CAT2120000
Name2CAT2220000
Name2CAT2320000
Name2CAT2420000

 

I am trying to create a matrix visual with this data which will be filtered on Quarter #. When filtered it will show 3 values for amount

A. Current quarter value - easily achievable,

B. Yearly Total - DAX to ignore the Quarter filter and calculate the sum of amount

C. YTD Running total - DAX to respect the Quarter Filter and calculate the sum of amount for all period <=Quarter Filter

 

I am currently generating the following which satisfies A

Capture.JPG

How can I generate the folowing

NameCATABC
Name1CAT13000100006000
Name1CAT23001000600
Name2CAT1100004000030000
Name2CAT2200008000060000

 

Thank you in advance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs
1 ACCEPTED SOLUTION
TomMartens
Super User
Super User

Hey,

 

I created these 3 measures:

A - Current quarter value = 
SUM('Table1'[Amount]) 
B - Yearly total = 
CALCULATE(
    [A - Current quarter value]
    ,ALL('Table1'[Quarter])
) 
C - YTD Running Total = 
CALCULATE(
    [A - Current quarter value]
    ,FILTER(
        ALL(Table1[Quarter])
        ,'Table1'[Quarter] <= MAX('Table1'[Quarter])
    )
)

These measures allow me to create a matrix visual and a table visual like so:

image.png

 

Instead of using the quarter column as a viual level filter I created a slicer.

Even if it's not necessary today, because your data model has just one table, I recommend to read through this article: https://www.daxpatterns.com/time-patterns/ From my experience it's always a good idea to have a dedicated Calendar table, even if it seems to make things more complicated at a first glance.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

View solution in original post

5 REPLIES 5
TomMartens
Super User
Super User

Hey,

 

I created these 3 measures:

A - Current quarter value = 
SUM('Table1'[Amount]) 
B - Yearly total = 
CALCULATE(
    [A - Current quarter value]
    ,ALL('Table1'[Quarter])
) 
C - YTD Running Total = 
CALCULATE(
    [A - Current quarter value]
    ,FILTER(
        ALL(Table1[Quarter])
        ,'Table1'[Quarter] <= MAX('Table1'[Quarter])
    )
)

These measures allow me to create a matrix visual and a table visual like so:

image.png

 

Instead of using the quarter column as a viual level filter I created a slicer.

Even if it's not necessary today, because your data model has just one table, I recommend to read through this article: https://www.daxpatterns.com/time-patterns/ From my experience it's always a good idea to have a dedicated Calendar table, even if it seems to make things more complicated at a first glance.

 

Regards,

Tom

 

 

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

@TomMartensthanks a lot for your help. It was urgent and I am so greatful to you and this community. It is really awesome.

 

My DAX side is not as strong as M. Can you please advise if there are some resources I can follow to learn DAX structurally and pick up the basic DAX concepts.

 

Thanks again. I picked my brain all morning for this.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

Hey @smpa01 

 

my favorite recommendation to start learning DAX is this book:

https://www.amazon.com/Beginning-DAX-Power-BI-Intelligence/dp/1484234766/ref=sr_1_1?keywords=Beginni...

by @Phil_Seamark 

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany
parry2k
Super User
Super User

@smpa01 there are lot of posts on time intelligence calculations and also lot of dax functions available, first and foremost, it is best practice to have date dimension in your model (lot of post on this as well) and then all these calculations become super easy.

 

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

@parry2k  thanks. Can you please post some URL for date dimension tables here if you happen to have them handy by chance.

Did I answer your question? Mark my post as a solution!
Proud to be a Super User!
My custom visualization projects
Plotting Live Sound: Viz1
Beautiful News:Viz1, Viz2, Viz3
Visual Capitalist: Working Hrs

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.