Forum Discussion
Total between Two Different Dates in Different Columns
- 6 years ago
Hi @JCPO ,
I created a dedicated calendar table with this DAX statement:
Calendar = var DateStart = MIN('Sheet'[Receipt Date]) var DateEnd = MAX('Sheet'[Final Dispatch Date]) return ADDCOLUMNS( ADDCOLUMNS( CALENDAR( DateStart , DateEnd ) , "weeknum iso" , WEEKNUM(''[Date] , 21) , "year" , YEAR(''[Date]) ) , "year iso" , IF([weeknum iso] < 5 && WEEKNUM(''[Date]) > 50 , [year] + 1 , IF([weeknum iso] > 50 && WEEKNUM(''[Date]) < 5 , [year] - 1 , [year] ) ) )Then I expanded the existing table in your Excel sheet as follows:
Sheet Expanded = GENERATE( 'Sheet' , DATESBETWEEN('Calendar'[Date] , 'Sheet'[Receipt Date] , 'Sheet'[Final Dispatch Date] ) )This expands the existing 26k rows to 12 million rows 🙂
I created a relationship between the calendar table and the "Expanded Sheet" table:
Note that the original table "Sheet" is hidden, as I no longer use this table for data visualization.
I created a measure:
Total Inventory = SUMX( VALUES('Sheet Expanded'[SKU Code]) , var _lastdate = CALCULATE(MAX('Calendar'[Date])) return CALCULATE(SUM('Sheet Expanded'[Inventory]) , 'Calendar'[Date] = _lastdate) )This allows you to create a chart like this:
Here you will find the pbix:
https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EbvQUuS6RAdBh82ACfyELloBR1EOxXCaIWhQDYluT0KsEw?e=AhlXgMHopefully, this provides what you're looking for.
Best regards
Tom
Hi @JCPO ,
I created a dedicated calendar table with this DAX statement:
Calendar =
var DateStart = MIN('Sheet'[Receipt Date])
var DateEnd = MAX('Sheet'[Final Dispatch Date])
return
ADDCOLUMNS(
ADDCOLUMNS(
CALENDAR( DateStart , DateEnd )
, "weeknum iso" , WEEKNUM(''[Date] , 21)
, "year" , YEAR(''[Date])
)
, "year iso" ,
IF([weeknum iso] < 5 && WEEKNUM(''[Date]) > 50
, [year] + 1
, IF([weeknum iso] > 50 && WEEKNUM(''[Date]) < 5 ,
[year] - 1 ,
[year]
)
)
)
Then I expanded the existing table in your Excel sheet as follows:
Sheet Expanded =
GENERATE(
'Sheet'
, DATESBETWEEN('Calendar'[Date] , 'Sheet'[Receipt Date] , 'Sheet'[Final Dispatch Date] )
)
This expands the existing 26k rows to 12 million rows 🙂
I created a relationship between the calendar table and the "Expanded Sheet" table:
Note that the original table "Sheet" is hidden, as I no longer use this table for data visualization.
I created a measure:
Total Inventory =
SUMX(
VALUES('Sheet Expanded'[SKU Code])
, var _lastdate = CALCULATE(MAX('Calendar'[Date]))
return
CALCULATE(SUM('Sheet Expanded'[Inventory]) , 'Calendar'[Date] = _lastdate)
)
This allows you to create a chart like this:
Here you will find the pbix:
https://tommartens-my.sharepoint.com/:u:/g/personal/tom_minceddata_com/EbvQUuS6RAdBh82ACfyELloBR1EOxXCaIWhQDYluT0KsEw?e=AhlXgM
Hopefully, this provides what you're looking for.
Best regards
Tom
This expands the existing 26k rows to 12 million rows How long did this take to complete? I have an inventory table, but thinking about alterring the beginning dates (or null dates), per: https://community.powerbi.com/t5/Desktop/Modelling-Best-Practices-with-Multiple-Date-Columns-amp-Values/m-p/1268007/highlight/true#M556706
4,000 items * Twenty years * 365 days = 29,200,000 rows.
Anonymous