Forum Discussion

Lobojo's avatar
Lobojo
Icon for Helper I rankHelper I
4 years ago
Solved

TOPN used with periodicity data

Hi,

 

I've learned how to use TOPN function and how to calculate month by month the cost of the vendor, starting from the table below

 

NameCostStart periodEnd period
Vendor150001.01.202230.06.2022
Vendor110001.01.202230.03.2022
Vendor1100001.07.202230.09.2022
Vendor2200001.01.202230.06.2022
Vendor220001.07.202231.12.2022
Vendor330001.01.202230.06.2022
Vendor340001.01.202230.03.2022
Vendor350001.07.202230.09.2022
Vendor420001.01.202230.06.2022
Vendor430001.07.202231.12.2022
Vendor440001.09.202231.12.2022
Vendor450001.01.2022

31.12.2022

 

 

Now I have to combine the two:

taking into consideration a filter/slicer that select 1 month, how to retrieve the 2 top costly vendor with the related month cost for this month considering to summarize the vendor costs only if they are considered in this particular month?

The costs are flat (meaning, for ex. for January, I will have the following total cost:

5001002000300400500

 = 3800

 

As a result, TOPN for Jan need to return me: vendor2= 2000 and vendor3,4=700

  • Hi,

    Please check the below picture and the attached pbix file.

    All measures are in the pbix file.

     

     

    Top two only: =
    VAR newtable =
        ADDCOLUMNS ( ALL ( Vendors[Name] ), "@cost", [Cost total:] )
    RETURN
        CALCULATE ( [Cost total:], KEEPFILTERS ( TOPN ( 2, newtable, [@cost], DESC ) ) )
    

1 Reply

  • Hi,

    Please check the below picture and the attached pbix file.

    All measures are in the pbix file.

     

     

    Top two only: =
    VAR newtable =
        ADDCOLUMNS ( ALL ( Vendors[Name] ), "@cost", [Cost total:] )
    RETURN
        CALCULATE ( [Cost total:], KEEPFILTERS ( TOPN ( 2, newtable, [@cost], DESC ) ) )