Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hey Community!
I have the following code I found online to provide me Prior Period calculations based on a slider. It works perfectly if you select one Month/Quater/Year. However, it fails when selecting multiple periods within the Month/Quarter/Year. Is there a way I change the code to get the desired results? I have tried replacing "HASONEVALUE" with "VALUES" and I get an error. Thank you in advance for your help!
Conc SM Gross PP:=
VAR DateCount =
COUNTROWS ( 'Report Date' )
VAR PeriodType =
SWITCH (
TRUE (),
AND (
HASONEVALUE ('Report Date'[CalendarYearID]),
DateCount = COUNTROWS ( PARALLELPERIOD ('Report Date'[Date], 0, YEAR ) )
), "Year",
AND (
HASONEVALUE ('Report Date'[CalendarQuarterID] ),
DateCount = COUNTROWS ( PARALLELPERIOD ( 'Report Date'[Date], 0, QUARTER ) )
), "Quarter",
AND (
HASONEVALUE ('Report Date'[CalendarMonthID] ),
DateCount = COUNTROWS ( PARALLELPERIOD ('Report Date'[Date], 0, MONTH ) )
), "Month",
AND (
HASONEVALUE ('Report Date'[CalendarYearID] ),
DateCount = COUNTROWS ( DATESYTD ('Report Date'[Date] ) )
), "YTD",
AND (
HASONEVALUE ('Report Date'[CalendarQuarterID]),
DateCount = COUNTROWS ( DATESQTD ( 'Report Date'[Date] ) )
), "QTD"
)
RETURN
SWITCH (
PeriodType,
"Year", CALCULATE ( [Conc SM Gross], PREVIOUSYEAR ('Report Date'[Date]) ),
"Quarter", CALCULATE ( [Conc SM Gross], PREVIOUSQUARTER ( 'Report Date'[Date] ) ),
"Month", CALCULATE ( [Conc SM Gross], PREVIOUSMONTH ('Report Date'[Date] )),
"YTD", CALCULATE ( [Conc SM Gross], PREVIOUSYEAR( 'Report Date'[Date] )),
"QTD", CALCULATE ( [Conc SM Gross], PREVIOUSQUARTER('Report Date'[Date] ) )
)
Hi @bigman24 ,
Do you have some sample data or preferably a sample pbix file.
Read this post to get your answer quickly.
https://community.powerbi.com/t5/Community-Blog/How-to-Get-Your-Question-Answered-Quickly/ba-p/38490
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
114 | |
99 | |
83 | |
70 | |
60 |
User | Count |
---|---|
150 | |
115 | |
104 | |
89 | |
65 |