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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Jensk
Frequent Visitor

How to get YTD values using string (text) columns in matrix

I want to calculate my running total by period. What do I need to do to get it work when using text columns (PERIOD_SHORT) in my matrix?

PERIOD_SHORT is sorted by PERIOD_ID in my table, but it does not work with my DAX.


My Data Model (keys are TRXDATE <> Date):

Jensk_2-1712324324131.png

 

My Measures:

 

 

Amount = SUMX(GL20000, GL20000[Amount])
Amount YTD Numeric = 
CALCULATE(
    [Amount],
    GL20000[PERIOD_ID] <= MAX(GL20000[PERIOD_ID])
)

 

 

 

Using PERIOD_ID as columns works because they can be ranked (year filter set to 2023):

Jensk_0-1712324106369.png

Using PERIOD_SHORT does not work because it is a string(text)  (year filter set to 2023) :

Jensk_1-1712324123588.png


My Data:

PERIOD_SHORTAmountTRXDATEPERIOD_IDAccount
Open10001-01-20230Account1
Jan10001-01-20231Account1
Feb10001-02-20232Account1
Mar10001-03-20233Account1
Apr10001-04-20234Account1
Maj10001-05-20235Account1
Jun10001-06-20236Account1
Jul10001-07-20237Account1
Aug10001-08-20238Account1
Sep10001-09-20239Account1
Okt10001-10-202310Account1
Nov10001-11-202311Account1
Dec10001-12-202312Account1
Open20001-01-20240Account1
Jan20001-01-20241Account1
Feb20001-02-20242Account1
Mar20001-03-20243Account1
Apr20001-04-20244Account1
Maj20001-05-20245Account1
Jun20001-06-20246Account1
Jul20001-07-20247Account1
Aug20001-08-20248Account1
Sep20001-09-20249Account1
Okt20001-10-202410Account1
Nov20001-11-202411Account1
Dec20001-12-202412Account1
1 ACCEPTED SOLUTION
Greg_Deckler
Super User
Super User

@Jensk Not sure if that will work with string text. Maybe if you have it sort by a numeric column (Sort by). You might also try this approach. Better Running Total - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Jensk ,

 

You can try formula like below:

YTD Amount = 
VAR SelectedPeriod =
    SELECTEDVALUE ( 'YourMatrix'[PERIOD_SHORT] )
RETURN
    CALCULATE (
        SUM ( 'YourMatrix'[Amount] ),
        FILTER (
            ALL ( 'YourMatrix' ),
            'YourMatrix'[PERIOD_SHORT] <= SelectedPeriod
                && 'YourMatrix'[TRXDATE] <= MAX ( 'Date'[Date] )
        )
    )

vkongfanfmsft_0-1712544768182.png

Best Regards,
Adamk Kong

 

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

Greg_Deckler
Super User
Super User

@Jensk Not sure if that will work with string text. Maybe if you have it sort by a numeric column (Sort by). You might also try this approach. Better Running Total - Microsoft Fabric Community



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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