cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
android1 Member
Member

Count if Date is earlier than selected date

Hi,

 

I am trying to count the distinct number of CarerRef if the StartDate is before a selected date in a slicer (this slicer gets its date from DateKey table). Only count CarerRef if DateLeft is blank.

 

Using: Active Point In Time = CALCULATE(DISTINCTCOUNT(vw_CrystalCarerAudit[CarerRef]),vw_CrystalCarerAudit[DateLeft] <> BLANK(),vw_CrystalCarerAudit[StartDate] <= RELATEDTABLE(DateKey),DateKey[Date])

 

but getting scalar value error: The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value.

 

What am I doing wrong here?

 

2018-04-05 19_29_11-Untitled - Power BI Desktop.png

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: Count if Date is earlier than selected date

Hi,
Give this a shot

 

Active Point In Time =
VAR selecteddate =
    SELECTEDVALUE ( DateKey[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( vw_CrystalCarerAudit[CarerRef] ),
        vw_CrystalCarerAudit[DateLeft] <> BLANK (),
        vw_CrystalCarerAudit[StartDate] <= selecteddate
    )


 

Try my new Power BI game Cross the River

View solution in original post

7 REPLIES 7
liu Frequent Visitor
Frequent Visitor

Re: Count if Date is earlier than selected date

Try:

 

Active Point In Time = CALCULATE(

     DISTINCTCOUNT(vw_CrystalCarerAudit[CarerRef]),

     FILTER(vw_CrystalCarerAudit[DateLeft] <> BLANK(),

                vw_CrystalCarerAudit[StartDate] <= RELATEDTABLE(DateKey),DateKey[Date]))

android1 Member
Member

Re: Count if Date is earlier than selected date

@liu

 

Doesn't like the 2 filters. It's giving me 'Too many arguments were passed to the FILTER function. The maximum argument count for the function is 2.'

liu Frequent Visitor
Frequent Visitor

Re: Count if Date is earlier than selected date

Try this instead:

 

Active Point In Time = CALCULATE

(

     DISTINCTCOUNT(vw_CrystalCarerAudit[CarerRef]),

     FILTER(vw_CrystalCarerAudit,

                vw_CrystalCarerAudit[DateLeft] <> BLANK() &&

                vw_CrystalCarerAudit[StartDate] <= RELATEDTABLE(DateKey),DateKey[Date])

)

android1 Member
Member

Re: Count if Date is earlier than selected date

Still not liking that ->

 

2018-04-05 20_48_48-Untitled - Power BI Desktop.png

liu Frequent Visitor
Frequent Visitor

Re: Count if Date is earlier than selected date

Hmm... I've yet to have to use RELATEDTABLE in a FILTER argument, but it seemed like because of the comma, it's assuming DateKey[Date] is a 3rd argument of FILTER, and not just part of RELATEDTABLE.

 

Perhaps try:

1. Put parenthesis around RELATEDTABLE(DateKey),DateKey[Date]

or

2. Drop the RELATEDTABLE(DateKey), and just use DateKey[Date].

Super User III
Super User III

Re: Count if Date is earlier than selected date

Hi,
Give this a shot

 

Active Point In Time =
VAR selecteddate =
    SELECTEDVALUE ( DateKey[Date] )
RETURN
    CALCULATE (
        DISTINCTCOUNT ( vw_CrystalCarerAudit[CarerRef] ),
        vw_CrystalCarerAudit[DateLeft] <> BLANK (),
        vw_CrystalCarerAudit[StartDate] <= selecteddate
    )


 

Try my new Power BI game Cross the River

View solution in original post

android1 Member
Member

Re: Count if Date is earlier than selected date

@Zubair_Muhammad That works great. Thank you very much.

Helpful resources

Announcements
Coming Soon: T-Shirt Design Contest

Coming Soon: T-Shirt Design Contest

Keep your eyes open for our upcoming T-shirt design contest!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors
Top Kudoed Authors