Forum Discussion

Micc_Che's avatar
Micc_Che
New Member
2 years ago

Problem with TREATAS measure on Bar Chart

Dear Power BI community,

 

I am new to Power BI, and I have a problem with treatas measure when using it to calculate count.

 

Below is a sample table, "Job":

IDJobDate
101Engineer18/10/2023
202Salesperson19/10/2023
303Teacher20/10/2023
404Designer21/10/2023
202Manager22/10/2023

 

And this is a date table for creating slicer "DateTable":

Date
18/10/2023
19/10/2023
20/10/2023
21/10/2023
22/10/2023

 

I want to create a bar chart with "Job" as x-axis, count of "ID" as y-axis, and have "DateTable"'s date as a dropdown slicer that allows only single select. When select the slicer, bar chart will show the count of job with date that is <= SELECTEDVALUE(Date):

 

And here is the problem, ID 202 was Salesperson at 19/10/2023, and change to Manager at 22/10/2023, but when 22/10/2023 is selected on slicer, Salesperson is still on the bar chart:

 

The measure I use for counting Job is:

 

CountJob =
VAR one =
SUMMARIZE(
    FILTER(Job, Job[Date] <= SELECTEDVALUE(DateTable[Date])),
    Job[ID],
    "Date", LASTDATE(Job[Date])
)
VAR two =
SUMMARIZE(
    FILTER(Job, Job[Date] <= SELECTEDVALUE(DateTable[Date])),
    Job[ID],
    Job[Job],
    "Date", LASTDATE(Job[Date])
)
VAR Joined = NATURALINNERJOIN(one, two)
RETURN CALCULATE(COUNT(Job[ID]), TREATAS(Joined, Job[ID], Job[Date], Job[Job]))
 
As we see in the image of Dax Studio below, ID 202 is shown as Manager:

 

Below is a comparison of the measure in Card, Table, and Bar Chart:

 

The count of job need to be only once for each ID, and date to be the latest date that is <= SELECTEDVALUE(Date).

I also need the slicer to be a single select dropdown.

There could be more duplicates for each ID with different dates.

Is there a way to make the bar chart to show 4 values without showing "Salesperson", in which ID 202 = Manager when date 22/10/2023 is selected?

 

Thank you very much.

1 Reply