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

Last Value of Each Person By Date Dynamically

Hi, 

 

I have been searching in the Power BI community and on Google for a way to get this figured out but have failed at every similar suggestions. 

 

I am trying to create a bar chart to show the (number of) people who answered yes to the question vs the (number of) people who answered no but dynamic by a date slicer. 

I would have a date slicer, a bar chart, and a table of names.

Date slicer shows a range and allows users to change the end date, with a title saying "As Of". 

Bar chart will have yes/no on the y-axis and x-axis showing the number of people. 

The total of the two bars would be the total number of people that have submitted an answer at all.

It would capture ONLY the last response of each person.

A person could answer no the day before but yes for today; it should only count the yes for this person.

 

To further illustrate this, I think a sample data will help.

Below is a sample data of what the format would look like.

With this data, if the date slicer has the end date of 7/2/2020, the total number of people of the two bars combined would be 4.

The number of people for answer Yes would be 1 (C), while the number of people for answer No would be 3 (A, B, C). 

This is because:

  • A answered No on 7/2.
  • B answered No on 7/1.
  • C answered Yes on 7/2.
  • D answered No on 7/1.

 

NameDateWork In Office
A7/1/2020No
A7/2/2020No
A7/3/2020Yes
A7/4/2020No
B7/1/2020No
B7/3/2020No
C7/2/2020Yes
C7/4/2020Yes
C7/5/2020Yes
D7/1/2020No
D7/3/2020Yes
D7/4/2020Yes

 

I tried things like the lastnonblank function and filter the table by the table and get max date of each person. 

 

If you could also tell me how I could count the number of people who has EVER answer yes before, that would be even more amazing.

 

Thank you for reading and considering possible solutions! 
I will keep trying.

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

Hi @Anonymous 

Firstly I build a slicer table as below.

Slicer = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Build a slicer

Result:

1.png

And I build a Work in Office Table as below.

Work in Office = VALUES('Table'[Work In Office])

2.png

Then I build a measure to achieve your goal.

Measure =

COUNTROWS (

    FILTER (

        VALUES ( 'Table'[Name] ),

        CALCULATE (

            IF (

                ISEMPTY (

                    FILTER (

                        'Table',

                        'Table'[Date] <= MAX ( Slicer[Date] )

                            && 'Table'[Work In Office] = "Yes"

                    )

                ),

                "No",

                "Yes"

            )

                = SELECTEDVALUE ( 'Work in Office'[Work In Office] )

        )

    )

)

Build Stacked bar chart as below:

3.png

The result is correct.

You can download the pbix file from this link:  Last Value of Each Person By Date Dynamically

 

Best Regards,

Rico Zhou

 

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-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

Could you tell me if your problem has been solved? If it is, kindly Accept it as the solution. More people will benefit from it. Or you are still confused about it, please provide me with more details about your problem or share me with your pbix file from your Onedrive for Business.

 

Best Regards,

Rico Zhou

v-rzhou-msft
Community Support
Community Support

Hi @Anonymous 

Firstly I build a slicer table as below.

Slicer = CALENDAR(MIN('Table'[Date]),MAX('Table'[Date]))

Build a slicer

Result:

1.png

And I build a Work in Office Table as below.

Work in Office = VALUES('Table'[Work In Office])

2.png

Then I build a measure to achieve your goal.

Measure =

COUNTROWS (

    FILTER (

        VALUES ( 'Table'[Name] ),

        CALCULATE (

            IF (

                ISEMPTY (

                    FILTER (

                        'Table',

                        'Table'[Date] <= MAX ( Slicer[Date] )

                            && 'Table'[Work In Office] = "Yes"

                    )

                ),

                "No",

                "Yes"

            )

                = SELECTEDVALUE ( 'Work in Office'[Work In Office] )

        )

    )

)

Build Stacked bar chart as below:

3.png

The result is correct.

You can download the pbix file from this link:  Last Value of Each Person By Date Dynamically

 

Best Regards,

Rico Zhou

 

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

Hi,

Has the other contributor answered your question?


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Ashish_Mathur
Super User
Super User

Hi,

You may download my PBI file from here.

Hope this helps.

Untitled.png


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Thank you Ashish_Mathur!

 

That solves my question about having a dynamic values with date slicer (last answer on and last answer was).

However, the countrow for Measure isn't working quite right. 

If you change the date slicer to 7/1 - 7/3, you get two bars of 3.

It should be 3 yes and 1 no.

Any suggestions on how to fix this?

amitchandak
Super User
Super User

@Anonymous , Try like

Yes Employee = countx(filter(summarize(Table, Table[Name], "_1",lastnonblankvalue(Table[Date],max(Table[Work In Office]))),[_1] ="Yes"),[Name])
No Employee =countx(filter(summarize(Table, Table[Name], "_1",lastnonblankvalue(Table[Date],max(Table[Work In Office]))),[_1] ="No"),[Name])

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.