Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

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.

Reply
bigman24
Frequent Visitor

Multiple Selections for HASONEVALUE - Prior Periods

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] ) )


)

1 REPLY 1
v-diye-msft
Community Support
Community Support

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

Community Support Team _ Dina Ye
If this post helps, then please consider Accept it as the solution to help the other members find it more
quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.