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

Dax calc help

Hello All,

 

I want help in formulating DAX for my use case.

Sample data is below. I want to show/FILTER only those rows whose latest month (MAR) value is >0.

Creating a if statement on the value field >0 is applying on all the months, BUT, I want it to apply only on latest MAR month.

 

As such Name "F" should filter out per my result. How can i get this. Please help.

 

NameMAR FEBJAN
A181416
B212213
C11716
D1922-12
E10-7-11
F-111016
G147

 

 

1 ACCEPTED SOLUTION
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

According to your description, your table seems to contain multiple month fields with values and you are try to filter on them to hide the last month records that than less than zero?

If this is a case, I'd like to suggest you do unpivot columns on your month fields to convert them to attitude and value fields.

Unpivot columns (Power Query) 

Then you can write a measure formula and use on 'visual level filter' to filter last month records.

Applying a measure filter in Power BI 

measure =
VAR list =
    ADDCOLUMNS (
        VALUES ( Table[Attribute] ),
        "Date", DATEVALUE ( [Attribute] & "/1" )
    )
VAR _lastMonth =
    MAXX ( list, [Date] )
VAR currValue =
    CALCULATE (
        SUM ( Table[Value] ),
        FILTER ( ALLSELECTED ( Table ), [Attribute] = FORMAT ( _lastMonth, "MMM" ) ),
        VALUES ( Table[Name] )
    )
RETURN
    IF (
        SELECTEDVALUE ( Table[Attribute] ) = FORMAT ( _lastMonth, "MMM" )
            && currValue > 0,
        "Y",
        "N"
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.

View solution in original post

5 REPLIES 5
v-shex-msft
Community Support
Community Support

Hi @Anonymous,

According to your description, your table seems to contain multiple month fields with values and you are try to filter on them to hide the last month records that than less than zero?

If this is a case, I'd like to suggest you do unpivot columns on your month fields to convert them to attitude and value fields.

Unpivot columns (Power Query) 

Then you can write a measure formula and use on 'visual level filter' to filter last month records.

Applying a measure filter in Power BI 

measure =
VAR list =
    ADDCOLUMNS (
        VALUES ( Table[Attribute] ),
        "Date", DATEVALUE ( [Attribute] & "/1" )
    )
VAR _lastMonth =
    MAXX ( list, [Date] )
VAR currValue =
    CALCULATE (
        SUM ( Table[Value] ),
        FILTER ( ALLSELECTED ( Table ), [Attribute] = FORMAT ( _lastMonth, "MMM" ) ),
        VALUES ( Table[Name] )
    )
RETURN
    IF (
        SELECTEDVALUE ( Table[Attribute] ) = FORMAT ( _lastMonth, "MMM" )
            && currValue > 0,
        "Y",
        "N"
    )

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Pragati11
Super User
Super User

Hi @Anonymous ,

 

Consider following sample data:

Pragati11_0-1597928630231.png

Create a caluclated column as follows:

newCol = CALCULATE(SUM(DaxCalc[Mar]), DaxCalc[Mar] > 0)
 
Move this to your table visual, you get following output:
q1.png 
 
Thanks,
Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

amitchandak
Super User
Super User

@Anonymous , this data should be unpivoted

https://radacad.com/pivot-and-unpivot-with-power-bi
Transpose : https://yodalearning.com/tutorials/power-query-helps-transposing-data/

 

an with year.

 

In this case, you can do is put a visual level filter of [MAR] >0

 

Greg_Deckler
Super User
Super User

@Anonymous - Is that really how your data looks? Thinking you should unpivot those month columns.


@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...
harshnathani
Community Champion
Community Champion

HI @Anonymous ,

 

Create a visual filter

 

1.jpg

 

Regards,
Harsh Nathani
Did I answer your question? Mark my post as a solution! Appreciate with a Kudos!! (Click the Thumbs Up Button)

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.