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

Find everything you need to get certified on Fabric—skills challenges, live sessions, exam prep, role guidance, and more. Get started

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

View solution in original post

2 REPLIES 2
v-kongfanf-msft
Community Support
Community Support

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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Helpful resources

Announcements
Europe Fabric Conference

Europe’s largest Microsoft Fabric Community Conference

Join the community in Stockholm for expert Microsoft Fabric learning including a very exciting keynote from Arun Ulag, Corporate Vice President, Azure Data.

Power BI Carousel June 2024

Power BI Monthly Update - June 2024

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

RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.