'powerbi previous time period comparison
I have found on youtube a nice tutorial of how to get a dynamic time period comparison (idk if I'm allowed to put a link so just type "Previous Dynamic Period using DAX in Power BI" by radacad)
So here's the dax code:
sales_prev_period =
var a = CALCULATE(
SUM('MESURES'[valeur]),
FILTER(ALL('MESURES'),
DATEVALUE('MESURES'[date_heure]) >= DATEVALUE('prev_date_stamp'[prev_start_date])
&& DATEVALUE('MESURES'[date_heure]) <= DATEVALUE('prev_date_stamp'[prev_end_date])
)
)
RETURN
IF(a > 1000000000, CONCATENATE(FORMAT(a, "######,##,,,.0G"), "Wh"),
IF(a > 1000000, CONCATENATE(FORMAT(a, "######,##,,.0M"), "Wh"),
IF(a > 1000, CONCATENATE(FORMAT(a, "######,##,.0k"), "Wh"),
CONCATENATE(FORMAT(a, "###0.0"), "Wh"))
)
)
This part returns me always Null / Empty
In contrary this bit of code just under (which is the same but with the "current" dates) always returns me the sum of all values (like if the filter wasn't applyed)
sales_current_period =
var a = CALCULATE(
SUM('MESURES'[valeur]),
FILTER(ALL('MESURES'),
DATEVALUE('MESURES'[date_heure]) >= DATEVALUE('prev_date_stamp'[start_date])
&& DATEVALUE('MESURES'[date_heure]) <= DATEVALUE('prev_date_stamp'[end_date])
)
)
RETURN
IF(a > 1000000000, CONCATENATE(FORMAT(a, "######,##,,,.0G"), "Wh"),
IF(a > 1000000, CONCATENATE(FORMAT(a, "######,##,,.0M"), "Wh"),
IF(a > 1000, CONCATENATE(FORMAT(a, "######,##,.0k"), "Wh"),
CONCATENATE(FORMAT(a, "####"), "Wh"))
)
)

Any idea where it can come from? how to solve it?
Thanks!
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
