Created
April 1, 2025 21:39
-
-
Save cbaragao/4f50bcf827ac50d2ba24056fdefd7ffb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /* | |
| Benefit: Automatically removes projections from consideration | |
| Make sure Dates[Year] and Dates[Month Name] are on the visual. | |
| Example for a Matrix put these columns in the Rows well in this order | |
| - Year | |
| - Month Name | |
| */ | |
| // Select a measure | |
| var offsetMeasure = Model.SelectMeasure(); | |
| // Select an offset column | |
| string offsetColumn = "CurrMonthOffset"; | |
| // Build DAX string | |
| string dax = | |
| @" | |
| VAR __SelOffset = SELECTEDVALUE( Dates[" + | |
| offsetColumn + "])" + | |
| @" | |
| VAR __Result = CALCULATE ( [" + | |
| offsetMeasure.Name + @"], FILTER ( ALL ( Dates[" + offsetColumn + | |
| @"], Dates[IsAfterToday]), Dates[CurrMonthOffset]<= __SelOffset && Dates[IsAfterToday] = FALSE), | |
| REMOVEFILTERS(Dates[Month Name], Dates[Month & Year])) | |
| RETURN | |
| __Result | |
| "; | |
| // Build measure name | |
| string measureName = "YTD Offset - " + offsetMeasure.Name; | |
| // Add the measure | |
| Model.Tables["1M"].AddMeasure(measureName, dax, "TI\\Offsets").FormatDax(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment