Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
2 years ago
Solved

Summarizing a table to align most recent dates

I've been unable to find/figure out how to summarize a table such that the data is aligned by most recent month, prior month, prior month -1, etc.  My goal is to be able to select the primary source ...
  • xifeng_L's avatar
    xifeng_L
    2 years ago

    Anonymous ,

     

    Sorry, I misunderstood your needs before. You can try below measure.

     

    (I can't very well restore your real date due to date formatting issues, so the results may change, but the logic should be correct.)

     

     

    Measure:

    Primary Source = 
    IF(HASONEFILTER('Fact'[Branch]),
        CALCULATE(
            VAR tempTable = SUMMARIZE('Fact','Fact'[source ],"Recent3MonthsTotal",SUM('Fact'[qty]))
            VAR MaxNbr = MAXX(tempTable,[Recent3MonthsTotal])
            RETURN
            MAXX(FILTER(tempTable,[Recent3MonthsTotal]=MaxNbr),'Fact'[source ]),
            TOPN(3,VALUES('Fact'[month]),'Fact'[month])
        )
    )

     

     

    Table Expression:

    Table Name = 
    ADDCOLUMNS (
        ALL ( 'Fact'[Branch] ),
        "Parimay Source",
            CALCULATE(
                CALCULATE(
                    VAR tempTable = SUMMARIZE('Fact','Fact'[source ],"Recent3MonthsTotal",SUM('Fact'[qty]))
                    VAR MaxNbr = MAXX(tempTable,[Recent3MonthsTotal])
                    RETURN
                    MAXX(FILTER(tempTable,[Recent3MonthsTotal]=MaxNbr),'Fact'[source ]),
                    TOPN(3,VALUES('Fact'[month]),'Fact'[month])
                )
            )
    )