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
Anonymous
Not applicable

Third condition in IF measure based on a date

Hi.
I have a matrix with the purpose to show what we have sold or not sold to a customer based on this measure:

Sold/Not Sold =
(IF(SUM('Salestable1'[Sales Quantity])>0,UNICHAR(9989),UNICHAR(10060)))
The matrix looks like this:
NorthernKarsten_0-1620039361321.png

 

My question:
I want to add a third condition to my measure that shows that if Sales Quantity >0 after 01.05.2021 and Sales Quantity<=0 before 01.05.2021 then a "🌟" should appear. 
Can someone help me to show me an example of how this could be done in my measure?
Thanks!
1 ACCEPTED SOLUTION
daxer-almighty
Solution Sage
Solution Sage

[Total Quantity] = SUM( 'Salestable1'[Sales Quantity] )

[Sold/Not Sold] =
var CutofffDate = DATE( 2021, 5, 1)
var TotalQuantityBeforeIsNotPositive =
    CALCULATE(
        [Total Quantity] <= 0,
        // 'Calendar' must be a proper date table
        // in the model connected to the fact table.
        'Calendar'[Date] < CutoffDate
    )
var TotalQuantityAfterOrOnIsPositive =
    CALCULATE(
        [Total Quantity] > 0,
        // 'Calendar' must be a proper date table
        // in the model connected to the fact table.
        'Calendar'[Date] >= CutoffDate
    )    
var TotalQuantityWeirdnessCondition = 
    TotalQuantityBeforeIsNotPositive
    &&
    TotalQuantityAfterOrOnIsPositive
var Result =
    switch( true(),
    
        TotalQuantityWeirdnessCondition,
            "<glowing star>",
            
        [Total Quantity] > 0,
            UNICHAR(9989),
            
        // When [Total Quantity] <= 0...
        UNICHAR(10060)
    )
return
    Result

View solution in original post

4 REPLIES 4
daxer-almighty
Solution Sage
Solution Sage

[Total Quantity] = SUM( 'Salestable1'[Sales Quantity] )

[Sold/Not Sold] =
var CutofffDate = DATE( 2021, 5, 1)
var TotalQuantityBeforeIsNotPositive =
    CALCULATE(
        [Total Quantity] <= 0,
        // 'Calendar' must be a proper date table
        // in the model connected to the fact table.
        'Calendar'[Date] < CutoffDate
    )
var TotalQuantityAfterOrOnIsPositive =
    CALCULATE(
        [Total Quantity] > 0,
        // 'Calendar' must be a proper date table
        // in the model connected to the fact table.
        'Calendar'[Date] >= CutoffDate
    )    
var TotalQuantityWeirdnessCondition = 
    TotalQuantityBeforeIsNotPositive
    &&
    TotalQuantityAfterOrOnIsPositive
var Result =
    switch( true(),
    
        TotalQuantityWeirdnessCondition,
            "<glowing star>",
            
        [Total Quantity] > 0,
            UNICHAR(9989),
            
        // When [Total Quantity] <= 0...
        UNICHAR(10060)
    )
return
    Result
Anonymous
Not applicable

@daxer-almighty that seems to work great!
It seems like I cant sort it by the three conditions in my matrix:

NorthernKarsten_0-1620113595375.png


Do you have a solution for this aswell?
And: is it possible to get those three conditions in a slicer visual?
Appreciate it!

Of course, it is possible. But what do you mean by "can't sort them"? The <glowing star> is something I put in but you have to change it to the right unicode character. Then, to sort them the way you want you have to use a trick called "zero-character space" and attach 0, 1 and 2 such spaces to the beginning of each of these unicode chars. Google for an article on sorting measure values on www.sqlbi.com or find the relevant vid on YT by Alberto Ferrari where he shows how to do it.

 

To get these chars in a slicer you have to create a disconnected table with these chars (plus the spaces) as values. It'll be a disconnected dimension.

amitchandak
Super User
Super User

@Anonymous , if date is in context of the visual then try like (correct the unicode)

 

Switch(true() ,
SUM('Salestable1'[Sales Quantity])>0 && Max(Date[Date]) >= date(2021,05,01),UNICHAR(9989),
SUM('Salestable1'[Sales Quantity])>0 && Max(Date[Date]) < date(2021,05,01),UNICHAR(10060),
,UNICHAR(10060))

 

If not they you have create measure for before and after 1st may

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.

Top Solution Authors