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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
MarkCBB
Helper V
Helper V

Rank Products, Stores (Over all time, Latest Month, Previous Month)

Hi there,

 

I have the following tables:

 

Sales - This is may Fact Table

Calendar - (With dates)

Product - This is a unique list

Stores - This is a unique list

 

I am looking to crete the following DAX Measures.

Top 10 Ranked Products over all Time, then for the latest Month, and for the Previous Month (Same for stores - But I can do this once I know how to do it for the products.

 

I then want to know the top 10 rank movments from Previous Month to latest Month, i.e. Product X went from Rank 56 to Rank 12 etc....

and then the same for Products that moved negitivly, i.e. Product Y went from Rank 2 to Rank 44. (so the worst Movments)

 

Our Products are fluctuating alot from month to month so we are trying to track the issue down, this will assist us in understanding the problem.

 

Regards,

Mark B

1 ACCEPTED SOLUTION
BetterCallFrank
Resolver IV
Resolver IV

Hi @MarkCBB

 

to get you started, here are some DAX formulas for

 

1) RANK of all times

Rank all time = 
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ), SUMX( RELATEDTABLE( _Sales ), _Sales[Sales Amt] ) )
)

2) RANK current month

Rank Curr Month = 
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ),
    CALCULATE( 
      SUMX( _Sales, _Sales[Sales Amt] ), 
      YEAR( _Sales[Date] ) = YEAR( NOW() ), 
      MONTH( _Sales[Date] ) = MONTH( NOW() ) 
    )
  )
)

3) RANK previous month

Rank Prev Month = 
VAR YYYYMM = 
  IF(
    MONTH(NOW()) > 1,
    YEAR(NOW())*100+MONTH(NOW())-1,
    (YEAR(NOW())-1)*100+12
  )
RETURN
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ),
    CALCULATE( 
      SUMX( _Sales, _Sales[Sales Amt] ), 
      YEAR( _Sales[Date] ) * 100 + MONTH( _Sales[Date] ) = YYYYMM 
    )
  )
)

I put the demo workbook at https://dl.dropboxusercontent.com/u/2676210/Rank%20All%20time%2C%20curr%20month%2C%20prev%20month.pb... for you to download.

 

As for the movements in the ranks: you can now of course create a table visual, put in the products, current month rank and previous month rank - and/or make new measures to calculate the movements

 

HTH,

Frank

View solution in original post

1 REPLY 1
BetterCallFrank
Resolver IV
Resolver IV

Hi @MarkCBB

 

to get you started, here are some DAX formulas for

 

1) RANK of all times

Rank all time = 
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ), SUMX( RELATEDTABLE( _Sales ), _Sales[Sales Amt] ) )
)

2) RANK current month

Rank Curr Month = 
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ),
    CALCULATE( 
      SUMX( _Sales, _Sales[Sales Amt] ), 
      YEAR( _Sales[Date] ) = YEAR( NOW() ), 
      MONTH( _Sales[Date] ) = MONTH( NOW() ) 
    )
  )
)

3) RANK previous month

Rank Prev Month = 
VAR YYYYMM = 
  IF(
    MONTH(NOW()) > 1,
    YEAR(NOW())*100+MONTH(NOW())-1,
    (YEAR(NOW())-1)*100+12
  )
RETURN
IF( HASONEVALUE( 'Product'[Product] ),
  RANKX( ALL( 'Product' ),
    CALCULATE( 
      SUMX( _Sales, _Sales[Sales Amt] ), 
      YEAR( _Sales[Date] ) * 100 + MONTH( _Sales[Date] ) = YYYYMM 
    )
  )
)

I put the demo workbook at https://dl.dropboxusercontent.com/u/2676210/Rank%20All%20time%2C%20curr%20month%2C%20prev%20month.pb... for you to download.

 

As for the movements in the ranks: you can now of course create a table visual, put in the products, current month rank and previous month rank - and/or make new measures to calculate the movements

 

HTH,

Frank

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.