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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
AmiraBedh
Most Valuable Professional
Most Valuable Professional

Create a from-to period date

I have the following date table :

YearMonthFromMonthToOrdreMonthNum
2020JanvierJanvier11
2020FévrierFévrier22
2020MarsMars33
2020AvrilAvril44
2020MaiMai55
2020JuinJuin66
2020JuilletJuillet77
2020AoûtAoût88
2020SeptembreSeptembre99
2020OctobreOctobre1010
2020NovembreNovembre1111
2020DécembreDécembre1212
2021JanvierJanvier131
2021FévrierFévrier142
2021MarsMars153
2021AvrilAvril164
2021MaiMai175
2021JuinJuin186
2021JuilletJuillet197
2021AoûtAoût208
2021SeptembreSeptembre219
2021OctobreOctobre2210
2021NovembreNovembre2311
2021DécembreDécembre2412

 

I am sorting the MonthFrom and the MonthTo based on the MonthNum.

 

I have the following filters :

capalt_0-1635955579084.png

Only one selection option is activated in them.

 

I am creating this measure to prevent that the user selects a higher month in the FROM filter than the TO filter ; 

 

FromToMeasure = IF(SELECTEDVALUE('Sorted Calendar'[MonthFrom]) > SELECTEDVALUE('Sorted Calendar'[MonthTo]), "Sélection invalide" , "")
 
Knowing that I removed the interaction between the months from and to filters.
I am putting this measure in a card but the problem it is returning blank in every condition.
 

Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696
1 ACCEPTED SOLUTION
amirabedhiafi
Impactful Individual
Impactful Individual

It's normal since you are comparing two string columns I suppose, so the result remains the same.

You are comparing for example "January" to "January" the two strings are equal so you won't have the error message.

Try the following : 

FromToMeasure = IF(SELECTEDVALUE('Sorted Calendar'[MonthNum]) > SELECTEDVALUE('Sorted Calendar'[MonthNum]), "Sélection invalide" , "")

 

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini

View solution in original post

3 REPLIES 3
PaulDBrown
Community Champion
Community Champion

The problem is that if you only use one table and this structure of slicers, the default behaviour will be to filter the table with and AND condition. In other words, if you select January in MontnFrom and then June in MonthTo the table is filtered to show rows in which both conditions are met (which is never, so that is why you get blanks. You have a couple of alternatives:
1) Use the month number as the slicer:

Slider.gif

2) Add two new unrealted tables for the MonthFrom and MonthTo (you only need the months and month numbers in these new tables. The model looks like this:

model.JPG

 Then create the follwoing measures to use as filter for the corresponding visuals in the Filter Pane:
1) Add this measure to the table visual's filter pane and set the resulting value to 1

 

Filter Result Table =
COUNTROWS (
    FILTER (
        'Date Table',
        'Date Table'[MonthNum] >= SELECTEDVALUE ( 'From Date'[MonthNum] )
            && 'Date Table'[MonthNum] <= SELECTEDVALUE ( 'To Date'[MonthNum] )
    )
)

 

2) Add this measure to the MonthFrom Slicer's filter pane and set the value to 1

 

Filter From = 
VAR SelValue = SELECTEDVALUE('To Date'[MonthNum])
RETURN
COUNTROWS(FILTER('From Date', 'From Date'[MonthNum] < SelValue))

 

3) Add this measure to the MonthTo Slicer's filter pane and set the value to 1

 

Filter To = 
VAR SelValue = SELECTEDVALUE('From Date'[MonthNum])
RETURN
COUNTROWS(FILTER('To Date', 'To Date'[MonthNum] > SelValue))

 

And this is what you get:

FromTo.gif

 

I've attached the sample PBIX file

 





Did I answer your question? Mark my post as a solution!
In doing so, you are also helping me. Thank you!

Proud to be a Super User!
Paul on Linkedin.






amirabedhiafi
Impactful Individual
Impactful Individual

It's normal since you are comparing two string columns I suppose, so the result remains the same.

You are comparing for example "January" to "January" the two strings are equal so you won't have the error message.

Try the following : 

FromToMeasure = IF(SELECTEDVALUE('Sorted Calendar'[MonthNum]) > SELECTEDVALUE('Sorted Calendar'[MonthNum]), "Sélection invalide" , "")

 

Amira Bedhiafi
Full Stack Business Intelligence Consultant @Capgemini
AmiraBedh
Most Valuable Professional
Most Valuable Professional

OMG didn't pay attention to that ! you saved my life thanks


Proud to be a Power BI Super User !

Microsoft Community : https://docs.microsoft.com/en-us/users/AmiraBedhiafi
Linkedin : https://www.linkedin.com/in/amira-bedhiafi/
StackOverflow : https://stackoverflow.com/users/9517769/amira-bedhiafi
C-Sharp Corner : https://www.c-sharpcorner.com/members/amira-bedhiafi
Power BI Community :https://community.powerbi.com/t5/user/viewprofilepage/user-id/332696

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.