Forum Discussion

gardas_swathi's avatar
gardas_swathi
Icon for Microsoft Employee rankMicrosoft Employee
6 years ago

Display sum only for max Inventory available date

Table - DAily Avg

DateIDDailyAvg
01/01/2020500
01/07/2020500
01/14/2020500
01/21/2020500

Table Inventory

DateIDInventory
01/01/20202000
01/02/20202222
01/03/20204566
01/04/20205632

I have a requirement where i have to calculate 4 weeks average value and display the value only against the latest inventory date. Future Dates and past dates should show blank. If there is no selecion on Date , then it should display the 4 week average too

Expected Output when filtered on date

DateInventory4 weeks avg
01/01/20202000 
01/02/20202222 
01/03/20204566 
01/04/20205632500

 

Expected Output when there is no selection on date

4 weeks avg
500

Measure i have developed so far is not giving the expected result. It shows values for previous dates as well.

 VAR DateSelection = SELECTEDVALUE('Date'[Calendar Date])
VAR Tab1 =  SUMMARIZE (
            'DailyAvg',
               " Final", CONVERT (
                SUM ( 'DailyAvg'[DailyAvg] )/28,
                DOUBLE
            )  ) 
   VAR Tab2= ADDCOLUMNS(Tab1,"InventoryDate",MAX('Inventory'[DateID]))
  VAR Val = SUMX(Tab2,[Consensus Final])
   VAR MDate= MAX('Inventory'[DateID]
RETURN IF(DateSelection=[MAxInventoryDate] OR DateSelection=BLANK() , result,BLANK())

 

Please help. Thanks in Advance

3 Replies