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
documentueh
Regular Visitor

cannot aggregate measure

Hi there,

 

I ve got a problem with measure dax. I cannot sum in group from measure which I ve created.

 

First I create a calculated column

 

totalday= (DATEDIFF(UW[Hieuluc Tu],UW[Hieuluc Den],DAY)

 

then I created a measure as below

earned_day = (CALCULATE(COUNTROWS('Date'),FILTER('Date','Date'[Date] >=MIN(UW[Hieuluc Tu]) && 'Date'[Date] <= MIN(UW[Hieuluc Den]))))/MIN(UW[totalday])
 
It's righ for each row calculation but when I do a sum for the year it's not correct anymore.
 
Do you have any idea?
 
Thanks for all!
a1.PNG

 

 
4 REPLIES 4
AntrikshSharma
Community Champion
Community Champion

See if this works:

earned_day =
SUMX (
    VALUES ( 'Date'[Year] ),
    DIVIDE (
        CALCULATE (
            COUNTROWS ( 'Date' ),
            FILTER (
                ALL ( 'Date' ),
                'Date'[Date] >= MIN ( UW[Hieuluc Tu] )
                    && 'Date'[Date] <= MIN ( UW[Hieuluc Den] )
            )
        ),
        VAR MinTotalDay =
            MIN ( UW[totalday] )
        RETURN
            IF ( MinTotalDay = 0, 1, MinTotalDay )
    )
)

The reason for infinity error is because at the denominator there is 0 for 2020  so you will have to check for the 0.

 

Thanks for your reply

 

Your dax can fix the infinity problem but it still doesnt correct the total of row.  I need to calculate the total by year. I cannot use sum function for a measure. The first measure just calculate for each row and I dont know how I can aggregrate for a group.

 

a2.PNG

Anonymous
Not applicable

You have to know what (and how) you want to calculate when you have many dates in the current context. If you don't know how to aggregate on the conceptual level (theory), you can't know the formula either (practice).

You have to give us the rule that produces the correct number if you have many days visible in the current context. I believe the calculation is correct on the day level or for the individual row in your UW table... You have not stated the problem in full, hence doubts.

Best
D

Can you please upload the file to google drive/one drive/dropbox and share the link and mark what values you want at the each row in the visual.

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