cancel
Showing results for
Did you mean:
Frequent Visitor

## Calculated Column that returns Distinct Count with a date slicer

Hi All,

This is a calculated column in Sheet (Mails) that returns 1 if someone in Sheet (Test) submitted twice (by distinct-counting the submitted on dates), 0.5, if someone submitted once, and 0 if someone didn't submitt at all.

Column =
VAR M = Mails[Mail]
RETURN
IF(
CALCULATE(
DISTINCTCOUNT(Test[SubmittedOn]),
FILTER(ALLSELECTED(Test),
Test[Submittedby] = M && Test[SubmittedOn] >= SELECTEDVALUE('Start Date'[Start Date]) && Test[SubmittedOn] <= SELECTEDVALUE('End Date'[End Date]))
)>=2,1,
IF(
CALCULATE(
DISTINCTCOUNT(Test[SubmittedOn]),
FILTER(ALLSELECTED(Test),
Test[Submittedby] = M && Test[SubmittedOn] >= SELECTEDVALUE('Start Date'[Start Date]) && Test[SubmittedOn] <= SELECTEDVALUE('End Date'[End Date]))
)=1,0.5,0
)
)

Start Date and End Time are
= GENERATESERIES(DATE(2020, 1,1), DATE(2060,12,31))

The problem is I want the returend value to be flitered by a date slicer on my dashboard, and I'm unable to do so using the DAX above.

But when I under the dates manually into the function, using Date(Year, Month, Day), it works perfectly.

Is there anyway to make this work in a calculated column?

Thanks.
1 ACCEPTED SOLUTION
Community Support

If you want to use date slicer to control the result, you need to create a measure not a calculate column.

We create a measure based on your business logic to meet your requirement.

1. We need to create a relationship between Mail table and Test table.

2. Then we can create a measure.

``````Measure =
VAR M =
MAX ( Mail[Mails] )
VAR _selected_Start =
SELECTEDVALUE ( 'Start Date'[Value] )
VAR _selected_End =
SELECTEDVALUE ( 'End Date'[Value] )
VAR _result1 =
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER (
ALLSELECTED ( Test ),
Test[Submittedby] = M
&& Test[SubmittedOn] >= _selected_Start
&& Test[SubmittedOn] <= _selected_End
)
) >= 2,
1,
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER (
ALLSELECTED ( Test ),
Test[Submittedby] = M
&& Test[SubmittedOn] >= _selected_Start
&& Test[SubmittedOn] <= _selected_End
)
) = 1,
0.5,
0
)
)
VAR _result2 =
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER ( ALLSELECTED ( Test ), Test[Submittedby] = M )
) >= 2,
1,
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER ( ALLSELECTED ( Test ), Test[Submittedby] = M )
) = 1,
0.5,
0
)
)
RETURN
IF (
ISBLANK ( _selected_Start ) || ISBLANK ( _selected_End ),
_result2,
_result1
)``````

3. At last we create two slicers based on Start Date and End Date.

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

Best regards,

Community Support Team _ zhenbw

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

4 REPLIES 4
Community Support

If you want to use date slicer to control the result, you need to create a measure not a calculate column.

We create a measure based on your business logic to meet your requirement.

1. We need to create a relationship between Mail table and Test table.

2. Then we can create a measure.

``````Measure =
VAR M =
MAX ( Mail[Mails] )
VAR _selected_Start =
SELECTEDVALUE ( 'Start Date'[Value] )
VAR _selected_End =
SELECTEDVALUE ( 'End Date'[Value] )
VAR _result1 =
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER (
ALLSELECTED ( Test ),
Test[Submittedby] = M
&& Test[SubmittedOn] >= _selected_Start
&& Test[SubmittedOn] <= _selected_End
)
) >= 2,
1,
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER (
ALLSELECTED ( Test ),
Test[Submittedby] = M
&& Test[SubmittedOn] >= _selected_Start
&& Test[SubmittedOn] <= _selected_End
)
) = 1,
0.5,
0
)
)
VAR _result2 =
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER ( ALLSELECTED ( Test ), Test[Submittedby] = M )
) >= 2,
1,
IF (
CALCULATE (
DISTINCTCOUNT ( Test[SubmittedOn] ),
FILTER ( ALLSELECTED ( Test ), Test[Submittedby] = M )
) = 1,
0.5,
0
)
)
RETURN
IF (
ISBLANK ( _selected_Start ) || ISBLANK ( _selected_End ),
_result2,
_result1
)``````

3. At last we create two slicers based on Start Date and End Date.

If it doesn’t meet your requirement, could you please show the exact expected result based on the table that you have shared?

BTW, pbix as attached.

Best regards,

Community Support Team _ zhenbw

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

Frequent Visitor

Genius, Thanks.

Super User IV

@NaderSaeed ,Can you share sample data and sample output in table format?

Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Frequent Visitor

Sheet(Test)

Sheet (Mail)

The Sheet (Mail) has all the databbase for all emails, and the Sheet (Test) only has the ones who have submitted, so I'm distinct-counting the SubmittedOn Coulmn as it'd be the best indicator in our case.

Announcements

#### Join us for our User Group Public Preview!

Power BI User Groups are coming! Make sure you’re among the first to know when user groups go live for public preview.

#### The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors