Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code FABINSIDER for a $400 discount.
Register nowGet inspired! Check out the entries from the Power BI DataViz World Championships preliminary rounds and give kudos to your favorites. View the vizzies.
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
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code FABINSIDER for a $400 discount!
Check out the February 2025 Power BI update to learn about new features.
User | Count |
---|---|
126 | |
115 | |
69 | |
62 | |
46 |