Forum Discussion

icdns's avatar
icdns
Icon for Post Patron rankPost Patron
2 years ago
Solved

YTD value (not cumulative)

Hello, 

 

I would like to ask for your help. I would like to get the YTD value of consumer count. But the thing, it SHOULD NOT be cummulative. I just want to get the max value of the date available. I do have a calendar date linked to the sales table. 

 

Example: 

In this table, the YTD value of the consumer count is 380. Since it is the latest data. 

Year

(from Date dimension)

Month

(from Date dimension)

Consumer Count

(from fact table)

2023Jan331
2023Feb332
2023Mar333
2023Apr336
2023May338
2023Jun339
2023Jul340
2023Aug345
2023Sep356
2023Oct360
2023Nov369
2023Dec380

 

Could somebody help me. 

 

Thannks!

  • Anonymous's avatar
    Anonymous
    2 years ago

    Hi icdns ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    FactTable:

    DateTable = ADDCOLUMNS(CALENDAR(DATE(2023,1,1),DATE(2023,12,31)),"year",YEAR([Date]),"monthno",MONTH([Date]),"month",FORMAT([Date],"mmm"))

    (2) We can create a measure. 

    Measure =
    VAR _maxdate =
        CALCULATE ( MAX ( 'FactTable'[Date] ), ALLSELECTED ( 'FactTable' ) )
    RETURN
        CALCULATE (
            SUM ( 'FactTable'[YTD] ),
            FILTER (
                ALL ( 'DateTable' ),
                'DateTable'[year] = YEAR ( _maxdate )
                    && 'DateTable'[monthno] = MONTH ( _maxdate )
            )
        )
    

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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

2 Replies

  • Daniel29195's avatar
    Daniel29195
    Icon for Community Champion rankCommunity Champion

    Hello icdns 

     

     

    Measure = 
    var datasource =
    
    addcolumns(
    allselected(Data[Date]),
    "@x"  ,
    calculate(
    SUM(Data[Sales]))
    
    )
    
    var max_data = 
    MAXX(
        datasource,
        [@x]
        
    )
    
    return max_data

     

     

    edit the above vode according to your tablenames and colum names.

     

     

     

    If my answer helped sort things out for you, i would appreciate a thumbs up 👍 and mark it as the solution !
    It makes a difference and might help someone else too. Thanks for spreading the good vibes! 🤠

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi icdns ,

     

    According to your description, here are my steps you can follow as a solution.

    (1) This is my test data.  

    FactTable:

    DateTable = ADDCOLUMNS(CALENDAR(DATE(2023,1,1),DATE(2023,12,31)),"year",YEAR([Date]),"monthno",MONTH([Date]),"month",FORMAT([Date],"mmm"))

    (2) We can create a measure. 

    Measure =
    VAR _maxdate =
        CALCULATE ( MAX ( 'FactTable'[Date] ), ALLSELECTED ( 'FactTable' ) )
    RETURN
        CALCULATE (
            SUM ( 'FactTable'[YTD] ),
            FILTER (
                ALL ( 'DateTable' ),
                'DateTable'[year] = YEAR ( _maxdate )
                    && 'DateTable'[monthno] = MONTH ( _maxdate )
            )
        )
    

    (3) Then the result is as follows.

     

    If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

     

    Best Regards,

    Neeko Tang

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