'Power Bi Eliminate Hard Coding in Measures
I have many measures created with different sets of values Hard-Coded.
For example, user name, Month, etc., and these values change once in 3 months or so.
Meas1 = CALCULATE(sum(Project[Amount]), DATEVALUE(Project[Period])=DATEVALUE("2021-09-15"))
Above 2021-09-15 is in multiple places, I would like to eliminate this hard coding within the measure. And if the month value changes to 2021-12-15 for example, would like to make it in a single place and all the measure gets updated accordingly.
Any help would be much appreciated.
I tried the below suggestion to use Testdate = datevalue("2021-09-15"). this is not giving the expected result for me.
In this case, I cannot use Testdate directly I get this error. 'A function 'calculate' has been used in true/false expression....', so I used filter.
Meas1 = CALCULATE(sum(Project[Amount]), filter(Project, DATEVALUE(Project[Period])= Project[Testdate]))
But now the expected result changes. Please see thebelow img.
Hard Coding gives me the expected results.
Regards, David
Solution 1:[1]
You can create a measure:
TestDate = DATEVALUE("2021-09-15")
you can then reference this measure in all the others. Once you need to change it, you change it only in the TestDate measure.
You can also create it as a Parameter in the report. That way, you would be able to change it in the Power BI service directly when needed.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | SamBouKoa |

