Forum Discussion
Utilization hours difference between following days
- 6 years ago
Hey TDys ,
this DAX allows is creating a calculated column:
previous smu = var instance = 'EquipmentSMU_API_Daily'[SERIALID] var currentDate = EquipmentSMU_API_Daily[TRANSDATE] var smu = 'EquipmentSMU_API_Daily'[Total SMU] var prevdate = MAXX( FILTER( ALL(EquipmentSMU_API_Daily) , 'EquipmentSMU_API_Daily'[SERIALID] = instance && 'EquipmentSMU_API_Daily'[TRANSDATE] < currentDate ) , [TRANSDATE] ) return SUMX( FILTER( ALL(EquipmentSMU_API_Daily) , 'EquipmentSMU_API_Daily'[SERIALID] = instance && 'EquipmentSMU_API_Daily'[TRANSDATE] = prevdate ) , [Total SMU] )Here is a screenshot from the table of your sample pbix (please be aware that a serialid is filtered and sorted (ascending) by TRANSDATE:
It will be very easy to calculate the change, just put "smu -" in front of the final SUMX.
A notion, solving this kind of problem (I call them, sorted (by something, here TRANDATE) sets (a set of something, here TRANDATE, grouped by SERIALID) is not the domain of the DAX engine where it could shine as it can. As the number of rows will grow, creating the column value will get slower and slower. Then you have to consider different approaches, like incremental refresh, or even a different architecture.Nevertheless, I'm hoping this will get you started.
Regards,
Tom
Hey TDys ,
this DAX allows is creating a calculated column:
previous smu =
var instance = 'EquipmentSMU_API_Daily'[SERIALID]
var currentDate = EquipmentSMU_API_Daily[TRANSDATE]
var smu = 'EquipmentSMU_API_Daily'[Total SMU]
var prevdate =
MAXX(
FILTER(
ALL(EquipmentSMU_API_Daily)
, 'EquipmentSMU_API_Daily'[SERIALID] = instance && 'EquipmentSMU_API_Daily'[TRANSDATE] < currentDate
)
, [TRANSDATE]
)
return
SUMX(
FILTER(
ALL(EquipmentSMU_API_Daily)
, 'EquipmentSMU_API_Daily'[SERIALID] = instance && 'EquipmentSMU_API_Daily'[TRANSDATE] = prevdate
)
, [Total SMU]
)
Here is a screenshot from the table of your sample pbix (please be aware that a serialid is filtered and sorted (ascending) by TRANSDATE:
It will be very easy to calculate the change, just put "smu -" in front of the final SUMX.
A notion, solving this kind of problem (I call them, sorted (by something, here TRANDATE) sets (a set of something, here TRANDATE, grouped by SERIALID) is not the domain of the DAX engine where it could shine as it can. As the number of rows will grow, creating the column value will get slower and slower. Then you have to consider different approaches, like incremental refresh, or even a different architecture.
Nevertheless, I'm hoping this will get you started.
Regards,
Tom
Thank you very much Tom. This is exactly what I needed.
Best regards;
Tomasz