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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Anonymous
Not applicable

Return values for blanks

Hello everyone, 

 

I am comparing statistics from Messi and Ronaldo. I have column with Date, Player and Goals. And I created a cumulative measure, which is as follows:

 

Cumulative goals = 
CALCULATE (
SUM ( 'Stats'[Goals] ),
FILTER (
ALL ( 'Stats' ),
'Stats'[Date] <= MAX ( 'Stats'[Date] )
&& 'Stats'[Player] = MAX ( 'Stats'[Player] )
))

The result is show in the left table:
MessiRonaldo.png

I am looking for output as in the right column. How can I change my measure to get to output with '0' for the one when the other one scored?



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

Hi @Anonymous ,

According to your description, here's my solution.

1.Create a new table.

Table =
GENERATE (
    VALUES ( Stats[Date] ),
    UNION ( ROW ( "Player", "Messi" ), ROW ( "Player", "Ronaldo" ) )
)

2.Create a calculated column in the new table.

Goal =
IF (
    MAXX (
        FILTER (
            ALL ( 'Stats' ),
            'Stats'[Date] = EARLIER ( 'Table'[Date] )
                && 'Stats'[Player] = EARLIER ( 'Table'[Player] )
        ),
        'Stats'[Goals]
    )
        <> BLANK (),
    MAXX (
        FILTER (
            ALL ( 'Stats' ),
            'Stats'[Date] = EARLIER ( 'Table'[Date] )
                && 'Stats'[Player] = EARLIER ( 'Table'[Player] )
        ),
        'Stats'[Goals]
    ),
    0
)

3.Create a measure.

Cumulative goals =
SUMX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date] <= MAX ( 'Table'[Date] )
            && 'Table'[Player] = MAX ( 'Table'[Player] )
    ),
    'Table'[Goal]
)

Get the expected result.

vkalyjmsft_0-1651054269368.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

6 REPLIES 6
v-yanjiang-msft
Community Support
Community Support

Hi @Anonymous ,

According to your description, here's my solution.

1.Create a new table.

Table =
GENERATE (
    VALUES ( Stats[Date] ),
    UNION ( ROW ( "Player", "Messi" ), ROW ( "Player", "Ronaldo" ) )
)

2.Create a calculated column in the new table.

Goal =
IF (
    MAXX (
        FILTER (
            ALL ( 'Stats' ),
            'Stats'[Date] = EARLIER ( 'Table'[Date] )
                && 'Stats'[Player] = EARLIER ( 'Table'[Player] )
        ),
        'Stats'[Goals]
    )
        <> BLANK (),
    MAXX (
        FILTER (
            ALL ( 'Stats' ),
            'Stats'[Date] = EARLIER ( 'Table'[Date] )
                && 'Stats'[Player] = EARLIER ( 'Table'[Player] )
        ),
        'Stats'[Goals]
    ),
    0
)

3.Create a measure.

Cumulative goals =
SUMX (
    FILTER (
        ALL ( 'Table' ),
        'Table'[Date] <= MAX ( 'Table'[Date] )
            && 'Table'[Player] = MAX ( 'Table'[Player] )
    ),
    'Table'[Goal]
)

Get the expected result.

vkalyjmsft_0-1651054269368.png

I attach my sample below for reference.

 

Best Regards,
Community Support Team _ kalyj

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

@v-yanjiang-msft This is great!! Thank you so much!

Anonymous
Not applicable

@amitchandak I don't, but I can create a date table. It will be a one-to-one relationship between the date column in my Stats table to the Date[date]. So, I am not sure if that work, but the Date table isn't linked to a specific player, if you're aiming for that.

amitchandak
Super User
Super User

@Anonymous , Try with +0

 

Cumulative goals =
CALCULATE (
SUM ( 'Stats'[Goals] ),
FILTER (
ALL ( 'Stats' ),
'Stats'[Date] <= MAX ( 'Stats'[Date] )
&& 'Stats'[Player] = MAX ( 'Stats'[Player] )
))+0

Anonymous
Not applicable

@amitchandak Thank you, and that would work, but in this case, it doesn't. 

I think it's because there's only one day per player: 

When Ronaldo scores and Messi doesn't, you have a row with the specific date, the number of goals and Ronaldo. 

@Anonymous , do you have a Separate date and player table ? In that case this might work

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.