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
tringuyenminh92
Memorable Member
Memorable Member

Pie chart showing wrong value for same measure when not filter date slicer

Hi all,

 

I got strange situation with calculated measure and pie chart/bar chart.  I have:

  1. Date slicer
  2. Calculated measure: (sum qty when there is fillter, if not, sum qty of the max date)
    sales amount = IF(ISFILTERED(FACT_SALES[Date]) , SUM(FACT_SALES[QTY]), 
    CALCULATE(SUM(FACT_SALES[QTY]),FILTER(FACT_SALES, FACT_SALES[Date]= max(FACT_SALES[Date])  ) )	  )

When i choose one date in slicer, everything is working correctly. but when select nothing. the pie chart with SITEID in legend showing wrong value. however it's correct without siteid.

 

when choose one datewhen choose one datewhen not choose date and have siteid in legend of pie chartwhen not choose date and have siteid in legend of pie chartthe pie chart in the right doesnt have siteid and it's showing correctlythe pie chart in the right doesnt have siteid and it's showing correctly

 

Did i miss something in my DAX expression?

1 ACCEPTED SOLUTION
v-haibl-msft
Employee
Employee

@tringuyenminh92

 

Please refer to following screenshot, if it is your desired result. Please try with following DAX expression.

 

sales amount = 
VAR MaxDate =
    CALCULATE (
        MAX ( FACT_SALES[Date] ),
        ALLSELECTED ( FACT_SALES[SITEID] ),
        ALLSELECTED ( FACT_SALES[Date] )
    )
RETURN
    IF (
        ISFILTERED ( FACT_SALES[Date] ),
        SUM ( FACT_SALES[QTY] ),
        CALCULATE (
            SUM ( FACT_SALES[QTY] ),
            FILTER ( FACT_SALES, FACT_SALES[Date] = MaxDate )
        )
    )

 

 

Best Regards,
Herbert

View solution in original post

2 REPLIES 2
v-haibl-msft
Employee
Employee

@tringuyenminh92

 

Please refer to following screenshot, if it is your desired result. Please try with following DAX expression.

 

sales amount = 
VAR MaxDate =
    CALCULATE (
        MAX ( FACT_SALES[Date] ),
        ALLSELECTED ( FACT_SALES[SITEID] ),
        ALLSELECTED ( FACT_SALES[Date] )
    )
RETURN
    IF (
        ISFILTERED ( FACT_SALES[Date] ),
        SUM ( FACT_SALES[QTY] ),
        CALCULATE (
            SUM ( FACT_SALES[QTY] ),
            FILTER ( FACT_SALES, FACT_SALES[Date] = MaxDate )
        )
    )

 

 

Best Regards,
Herbert

Hi @v-haibl-msft,

 

Thanks for your response. Your suggestion is not my point, but I could refer your expr and realize that if i use variable, it will work for my expectation:

 

Not working expr:

m = IF(ISFILTERED(FACT_SALES[Ngày]) , SUM(FACT_SALES[QTY]), 
CALCULATE(SUM(FACT_SALES[QTY]),FILTER(all(FACT_SALES), FACT_SALES[Ngày]=CALCULATE( max(FACT_SALES[Ngày]),all(FACT_SALES) )  ) )	  )

And working expr after refer your code:

sales amount = 
VAR MaxDate =
    CALCULATE (
        MAX ( FACT_SALES[Ngày] ),
		ALL(FACT_SALES)
    )
RETURN
    IF (
        ISFILTERED ( FACT_SALES[Ngày] ),
        SUM ( FACT_SALES[QTY] ),
        CALCULATE (
            SUM ( FACT_SALES[QTY] ),
            FILTER ( FACT_SALES, FACT_SALES[Ngày] = MaxDate )
        )
    )

2017-04-27_16h37_21.png

 

@v-haibl-msft: one more concern, is there any wrong with the old expression? (using all inside the filter method)

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.