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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
tim10
Helper I
Helper I

Validate Slicer Selection

Hello

 

I have a period column in a table that I am using as a slicer. It is of type date and I am using it as a Date Hierarchy. 

I need to validate if the user selected the same number of months in the years, for example: if in 2020, January and February are selected and in 2021, January, February and March are selected, i need it to display "months missing from selection". If there is a match in the number of months selected in multiple years, i need it to display "months selected correctly".

I have no idea how to start this.

Any suggestion is appreciated.

 

period.png

Thank you

1 ACCEPTED SOLUTION
parry2k
Super User
Super User

@tim10 here you go, add following measure

Month Selected = 
VAR __year = 
SUMMARIZE ( 
    'Calendar', [Year], "@Months", CONCATENATEX ( VALUES ( 'Calendar'[Month] ), [Month], "," ) 
)
VAR __status =
IF ( COUNTROWS ( VALUES ( 'Calendar'[Year] ) ) = 1, -1,
    COUNTX ( 
        SUMMARIZE ( __year, [@Months], "@Rowcount", COUNTROWS ( __year ) ), [@Rowcount] 
    ) 
)
RETURN
SWITCH ( 
    __status,
    1, "Valid Selection", 
    -1, "Invalid Selecton - Only months selected in one year",
    "Invalid Selection - not same months selected"
)

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

View solution in original post

7 REPLIES 7
parry2k
Super User
Super User

@tim10 here is a small video that shows the working of it

 

month selection.gif

 

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

I've tried your code and it seems to work for my scenario. Thank you for your support and also thank you to everyone that gave suggestions. 

parry2k
Super User
Super User

@tim10 here you go, add following measure

Month Selected = 
VAR __year = 
SUMMARIZE ( 
    'Calendar', [Year], "@Months", CONCATENATEX ( VALUES ( 'Calendar'[Month] ), [Month], "," ) 
)
VAR __status =
IF ( COUNTROWS ( VALUES ( 'Calendar'[Year] ) ) = 1, -1,
    COUNTX ( 
        SUMMARIZE ( __year, [@Months], "@Rowcount", COUNTROWS ( __year ) ), [@Rowcount] 
    ) 
)
RETURN
SWITCH ( 
    __status,
    1, "Valid Selection", 
    -1, "Invalid Selecton - Only months selected in one year",
    "Invalid Selection - not same months selected"
)

 

Check my latest blog post Comparing Selected Client With Other Top N Clients | PeryTUS  I would ❤ Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos to whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

parry2k
Super User
Super User

@tim10 one question. what happens if the user selects Jan/Feb in 2019 and Nov/Dec in 2020, still the user selected two months in both of the years but these are different months? Is this the right selection or month selection have to be the same for each year or just the count of month matter, not the actual months?



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

has to be the same months. basically i am trying to validate that a user compares the same periods, for some specific scenario. thank you

Jihwan_Kim
Super User
Super User

 

Picture1.png

 

count months : =
COUNTROWS(VALUES('Calendar'[Month Name]))

 

count years : =
COUNTROWS(VALUES('Calendar'[Year]))
 
Selection Validate Measure =
VAR monthscount =
COUNTROWS ( VALUES ( 'Calendar'[Month Name] ) )
VAR yearscount =
COUNTROWS ( VALUES ( 'Calendar'[Year] ) )
VAR newtablemonth =
ADDCOLUMNS ( ALLSELECTED ( 'Calendar'[Month] ), "@countyears", [count years :] )
VAR newtableyear =
ADDCOLUMNS (
ALLSELECTED ( 'Calendar'[Year] ),
"@countmonths", [count months :]
)
RETURN
IF (
monthscount = MINX ( newtableyear, [@countmonths] )
&& yearscount = MINX ( newtablemonth, [@countyears] ),
"Months selected correctly",
"Months missing from selection"
)
 
 

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


thank you for your reply. your solution only works if i select something in both years. if i only select in one of the years, it is no longer working and this is a scenario that would happen often. i appreciate your suggestion

 

not.png

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

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