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
apmulhearn
Helper III
Helper III

Need help with query - Sum based on select criteria with filtered date

Hello,

 

I need to be able to get a distinct count of the number of clients who satisfy the following criteria:

 

Based on the date range provided in the slider,

 

How many clients have 1 or more trips with End Date Prior to OR Equal to that latest date in that date range where the status is NOT Cancelled OR Transferred

AND

The Trip Code does NOT start with X or F.

 

Sample Data below... MANY thanks for help!

 

ClientId     EndDate      TripCode    Status

123451/1/2017XA908Completed
67891/12/2017BA807Completed
54322/4/2017XA908Cancelled
654322/10/2017SA306Transferred
980766/10/2018FA432Completed
5436784/3/2019BA999Completed
765434/2/2018BA346Completed
43256781/7/2018SA456Completed
43565/2/2019PEA095Completed
356892/1/2021PA043Booked
231454/2/2016PA434Completed
658795/4/2019XA908Cancelled
349035/2/2018BA807Booked
123453/2/2019XA908Completed
67892/19/2018SA306Completed
54325/6/2019FA432Cancelled
654327/4/2019BA999Transferred
980763/5/2018BA346Completed
5436782/1/2020SA456Completed
765434/2/2019PEA095Completed
43256785/3/2019PA043Transferred
43562/1/2019PA434Completed
356896/23/2017XA908Completed
2314511/3/2017PA043Completed
658796/1/2019PA434Cancelled
349037/16/2018FA432Completed
123455/10/2019XA908Completed
67894/13/2020BA807Booked
54327/17/2017XA908Booked
6543210/23/2021SA306Transferred
980769/23/2019FA432Booked
54367810/18/2018BA999Cancelled
765435/3/2019BA346Completed
43256786/6/2018SA456Completed
43567/8/2019PEA095Completed
3568910/4/2018PA043Completed
231455/1/2021PA434Completed
658798/16/2020BA999Completed
349039/17/2019BA346Completed
67894/10/2018BA664Cancelled
67892/10/2018XA444Completed
1 ACCEPTED SOLUTION

Hi @apmulhearn ,

You can create a measure as below to get the count of clients who meet the filter criteria, it will only get 10 distinct clients. Please check the below table, client 5432 and 12345 should not be in the list, as their TripCode start with "X".Client 65879 has one row which meet the filter criteria. You can find the attachment for the details.

Note: I create a date dimension table, its date field be used in slicer.

yingyinr_3-1626934443969.png

Count of clients = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[ClientId] ),
    FILTER (
        'Table',
        'Table'[EndDate] <= MAX ( 'Date'[Date] )
            && NOT ( 'Table'[Status] IN { "Cancelled", "Transferred" } )
                && NOT ( LEFT ( 'Table'[TripCode] ) IN { "X", "F" } )
    )
)

yingyinr_0-1626934179793.png

Best Regards

Community Support Team _ Rena
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

4 REPLIES 4
Fowmy
Super User
Super User

@apmulhearn 

Create the following measure:

Count of Clients = 
var __enddate = MAX(Table3[End Date]) return

CALCULATE(
    COUNT(Table3[Client ID]),
    Table3[End Date] <= __enddate,
    NOT Table3[Status] IN {"Cancelled","Transferred"},
    FILTER(
        DISTINCT(Table3[Trip Code]),
        NOT LEFT(Table3[Trip Code],1) IN {"X","F"}
    ) 
)

Fowmy_0-1626722852885.png

 



Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Hi @Fowmy 

I really appreciate the quick help...but in looking at your screenshot, I don't think that can be exactly what I'm looking for. Client ID 76543 only exists in the raw data 3 times, but your count shows 3 rows with that ID, one with a count of 2. 

Using the dates you've selected, this is the outcome I would have been seeking:

apmulhearn_0-1626724231982.png

 

Hi @apmulhearn ,

You can create a measure as below to get the count of clients who meet the filter criteria, it will only get 10 distinct clients. Please check the below table, client 5432 and 12345 should not be in the list, as their TripCode start with "X".Client 65879 has one row which meet the filter criteria. You can find the attachment for the details.

Note: I create a date dimension table, its date field be used in slicer.

yingyinr_3-1626934443969.png

Count of clients = 
CALCULATE (
    DISTINCTCOUNT ( 'Table'[ClientId] ),
    FILTER (
        'Table',
        'Table'[EndDate] <= MAX ( 'Date'[Date] )
            && NOT ( 'Table'[Status] IN { "Cancelled", "Transferred" } )
                && NOT ( LEFT ( 'Table'[TripCode] ) IN { "X", "F" } )
    )
)

yingyinr_0-1626934179793.png

Best Regards

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

@apmulhearn 

 

I am not at the PC now, change my COUNT to DISTINCTCOUNT and try

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

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.