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
ldavis4230
Frequent Visitor

Creating measures that look at slicer selections

Hello!

 

I'm attempting to create a report using measures so that the values will update dynamically based upon the user's slicer selections. I have four slicers that filter the data based on date:

Period 1 Start

Period 1 End

Period 2 Start

Period 2 End

 

I've been successful with several measures that filter on only one period, but am having trouble when trying to filter when either is true, meaning the date falls within Period 1 OR Period 2 (allowing for the possibility that they're not consecutive).

 

Here's my measure:

 

Product Count = CALCULATE(DISTINCTCOUNT('Product'[SKU]),
FILTER(Purchase,
DATESBETWEEN('Date of Purchase'[Purchase Date],SELECTEDVALUE('P1 Start'[1st Day of Month]),SELECTEDVALUE('P1 End'[Last Day of Month]))||
DATESBETWEEN('Date of Purchase'[Purchase Date],SELECTEDVALUE('P2 Start'[1st Day of Month]),SELECTEDVALUE('P2 End'[Last Day of Month]))
)
)
 
It seems to work okay until I attempt to add it into a table, when I get the below error.
error.PNG
 
Any thoughts on how to fix this, or an alternative solution?
Thanks so much!!
Lauren
1 ACCEPTED SOLUTION
v-lid-msft
Community Support
Community Support

Hi @ldavis4230

 

We can try to use the following measure to meet your requirement:

 

Product Count =
CALCULATE (
    DISTINCTCOUNT ( 'Product'[SKU] ),
    FILTER (
        Purchase,
        OR (
            AND (
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    >= SELECTEDVALUE ( 'P1 Start'[1st Day of Month], BLANK () ),
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    <= SELECTEDVALUE ( 'P1 End'[Last Day of Month], BLANK () )
            ),
            AND (
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    >= SELECTEDVALUE ( 'P2 Start'[1st Day of Month], BLANK () ),
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    <= SELECTEDVALUE ( 'P2 End'[Last Day of Month], BLANK () )
            )
        )
    )
)

 

If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


Best regards,

 

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

View solution in original post

3 REPLIES 3
v-lid-msft
Community Support
Community Support

Hi @ldavis4230

 

We can try to use the following measure to meet your requirement:

 

Product Count =
CALCULATE (
    DISTINCTCOUNT ( 'Product'[SKU] ),
    FILTER (
        Purchase,
        OR (
            AND (
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    >= SELECTEDVALUE ( 'P1 Start'[1st Day of Month], BLANK () ),
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    <= SELECTEDVALUE ( 'P1 End'[Last Day of Month], BLANK () )
            ),
            AND (
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    >= SELECTEDVALUE ( 'P2 Start'[1st Day of Month], BLANK () ),
                RELATED ( 'Date of Purchase'[Purchase Date] )
                    <= SELECTEDVALUE ( 'P2 End'[Last Day of Month], BLANK () )
            )
        )
    )
)

 

If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to One Drive and share the link here.


Best regards,

 

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

Thank you so much @v-lid-msft ! 

amitchandak
Super User
Super User

Try like

Product Count = CALCULATE(DISTINCTCOUNT('Product'[SKU]),
FILTER(Purchase,
DATESBETWEEN('Date of Purchase'[Purchase Date],minx('P1 Start',SELECTEDVALUE('P1 Start'[1st Day of Month])),
maxx('P1 Start',SELECTEDVALUE('P1 End'[Last Day of Month])))||
DATESBETWEEN('Date of Purchase'[Purchase Date],minx('P2 Start',SELECTEDVALUE('P2 Start'[1st Day of Month]))
,maxx('P2 Start',SELECTEDVALUE('P2 End'[Last Day of Month]))
)))

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution. In case it does not help, please provide additional information and mark me with @
Thanks. My Recent Blog -
Winner-Topper-on-Map-How-to-Color-States-on-a-Map-with-Winners , HR-Analytics-Active-Employee-Hire-and-Termination-trend
Power-BI-Working-with-Non-Standard-Time-Periods And Comparing-Data-Across-Date-Ranges

Connect on Linkedin

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.