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
billabang
Frequent Visitor

Filter by Date then get most recent joined result - Display count of records

Hi 

 

I am new to Power BI but not to working with data. I am struggling to do something that I could have achieved with other tools so hoping it should be relatively straight forward and just my lack of knowledge in PowerBI that is causing the problem.

 

I have two tables with the data I need to use, a Main Table and a Sub Table which can be linked by the RecordID.

 

Main Table Example:

RecordIDDescriptionPriority
1Record11
2Record21
3Record32
4Record42
5Record53

 

Sub Table Example

RecordIDStatusDate
1

APPR

01/12/2019
1COMP01/01/2020
2WAPPR01/11/2019
2APPR01/12/2019
2COMP01/01/2020
3APPR01/01/2020
4WAPPR01/12/2019
4APPR01/12/2019
4COMP01/01/2020
4CAN01/01/2020
5WAPPR01/01/2020
5APPR01/01/2020

 

I need to display a count of OPEN records (not COMP or CAN status) by priority at any given date - currently just looking to select a month in a slicer/filter and it would show the count based upon the end day of that month.

 

So if I chose DECEMBER-2019 I should get a bar chart showing that there were 3 projects open (RecordID 1,2 and 4) but seperated into  the bar's for each priority. 

In this case I would see Two records at priority 1 and One record at priority 2.

 

If this was pure SQL I would simply add a column to the Main Table that looks up the current Status based upon the date filter. I could then count/group the projects by priority. 

 

I have tried a bunch of different New Measures, joined tables and various bits and pieces from forums that I shall not confuse the matter with here.

 

Please can someone assist me? I have an example Power BI Desktop file with this data in and a Date Table but cannot see the attachment option as I create this post.

 

Thanks for any hep - it's much appreciated. I'm looking to understand this as fully as possible so I apologise if any of my follow up questions are a bit naive as far as knowledge of PowerBI goes.

1 ACCEPTED SOLUTION

Hi @billabang ,

 

Please modify the Measure countrecord as below.

countrecord = 
CALCULATE (
    DISTINCTCOUNT ( Main[RecordID] ),
    FILTER (
        Sub,
        Sub[Date]
            = CALCULATE (
                MAX ( Sub[Date] ),
                FILTER (
                    ALLEXCEPT ( Sub, Sub[RecordID] ),
                    FORMAT ( Sub[Date], "YYYYMM" ) = SELECTEDVALUE ( 'CALENDAR'[yearmonth] )
                )
            )
            && Sub[Status] <> "COMP"
            && Sub[Status] <> "CAN"
    )
)

 Result would be shown as below.

4.PNG5.PNG6.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

View solution in original post

4 REPLIES 4
v-jayw-msft
Community Support
Community Support

Hi @billabang ,

 

Please check following steps as below.

1# Create a CALENDAR table and a yearmonth calculated column.

 

CALENDAR = CALENDARAUTO()

yearmonth = FORMAT('CALENDAR'[Date],"YYYYMM")

 

2# Create a measure.

 

countrecord = 
CALCULATE (
    DISTINCTCOUNT ( Main[RecordID] ),
    FILTER (
        Sub,
        FORMAT ( Sub[Date], "YYYYMM" ) = SELECTEDVALUE ( 'CALENDAR'[yearmonth] )
            && Sub[Status] <> "COMP"
            && Sub[Status] <> "CAN"
    )
)

 

 Result would be shown as below.

1.PNG2.PNG3.PNG

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Thanks Jay

 

I failed to provide an example where the project may have been re-opened within a month so I cant just discount COMP altogether. It depends on if the COMP/CAN is the final state in that selected month.

 

I will try what you have posted anyway as it's good practice for me but do you have any idea how I can only get the LATEST status from the subtable and then perform the count accross the records?

 

I appreciate your assistance.

Hi @billabang ,

 

Please modify the Measure countrecord as below.

countrecord = 
CALCULATE (
    DISTINCTCOUNT ( Main[RecordID] ),
    FILTER (
        Sub,
        Sub[Date]
            = CALCULATE (
                MAX ( Sub[Date] ),
                FILTER (
                    ALLEXCEPT ( Sub, Sub[RecordID] ),
                    FORMAT ( Sub[Date], "YYYYMM" ) = SELECTEDVALUE ( 'CALENDAR'[yearmonth] )
                )
            )
            && Sub[Status] <> "COMP"
            && Sub[Status] <> "CAN"
    )
)

 Result would be shown as below.

4.PNG5.PNG6.PNG

Pbix as attached.

 

Best Regards,

Jay

Community Support Team _ Jay Wang

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

Community Support Team _ Jay
If this post helps, then please consider Accept it as the solution
to help the other members find it.

Thanks - I think that has done the trick!

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.