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

Next up in the FabCon + SQLCon recap series: The roadmap for Microsoft SQL and Maximizing Developer experiences in Fabric. All sessions are available on-demand after the live show. Register now

Reply
andybamber
Helper III
Helper III

Row Context

Hello!

 

Hopefully someone can help me with an issue im facing. In the PBIX below I have a sample of my dataset. If you look at the visuals, the first one correctly shows a distinct count of 8... the second one though, when i try to visualise by role, does not show teh correct count. I presume this is due to row context, and the fact that some resource_keys have a change in role name in the same month. So the question is, how can i build a measure (or any other solution) that will only count/display the most recent occurance for that resource_key

 

https://www.dropbox.com/s/pvknpdf82o70y72/PBIX_example.pbix?dl=0 

 

Cheers

 

Andy

1 ACCEPTED SOLUTION

Here is one way to do it.  This makes a virtual table of each resource and two columns - the max date within this role and the max date across all roles.  It then counts only those where those snapshot dates are the same.

 

NewMeasure =
VAR summary =
    ADDCOLUMNS (
        DISTINCT ( Sheet1[resource_key] ),
        "@maxdate",
            CALCULATE (
                MAX ( Sheet1[snaphot_stamp] )
            ),
        "@maxall",
            CALCULATE (
                MAX ( Sheet1[snaphot_stamp] ),
                ALL ( Sheet1[primary_role] )
            )
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@maxdate] = [@maxall]
        )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

4 REPLIES 4
lbendlin
Super User
Super User

The measure works as designed. You did not include the resource key in any visual so it has no impact on the result.

 

Please be more specific what you are trying to achieve.

@lbendlin  Hey there! thanks for the reply... so, the first visual gives me exactly what i require, which is a distinct count of resource_key based on the max snaphot date in that month.

 

What i am trying to acheive in the other visual is to show the distinct count of resource_key, again based on max snapshot data in the month, but then break that down to show it by primary_role... however, as an example, resource_key = 5048382 on 1/10/10 had a primary_role = _human resource manager, on 12/10/20 this had changed to _P&C Business Partner... the visual is actually picking up both of these, when what i really require is for it to only pick up the primary_role associated with the max snapshot date of 12/10/20. This would then mean that the numbers on visual 1 for the month would equal those on visual 2....

 

Cheers

Andy

Here is one way to do it.  This makes a virtual table of each resource and two columns - the max date within this role and the max date across all roles.  It then counts only those where those snapshot dates are the same.

 

NewMeasure =
VAR summary =
    ADDCOLUMNS (
        DISTINCT ( Sheet1[resource_key] ),
        "@maxdate",
            CALCULATE (
                MAX ( Sheet1[snaphot_stamp] )
            ),
        "@maxall",
            CALCULATE (
                MAX ( Sheet1[snaphot_stamp] ),
                ALL ( Sheet1[primary_role] )
            )
    )
RETURN
    COUNTROWS (
        FILTER (
            summary,
            [@maxdate] = [@maxall]
        )
    )

 

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat  That's perfect! thanks Pat, much apprecaited... Andy

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.