Forum Discussion

Jensk's avatar
Jensk
Frequent Visitor
2 years ago
Solved

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):

 

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):

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


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

2 Replies

  • Anonymous's avatar
    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] )
            )
        )
    

    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.