Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Get Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now

Reply
Micc_Che
New Member

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):

Micc_Che_0-1697635782857.png

 

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:

Micc_Che_1-1697636060576.png

 

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:
Micc_Che_2-1697636680848.png

 

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

Micc_Che_3-1697636916171.pngMicc_Che_4-1697637009347.png

 

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 1
lbendlin
Super User
Super User

You need neither TREATAS nor your join when you have a proper data model

You should also disable auto date/time as soon as possible.

 

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

Helpful resources

Announcements
FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.

Top Solution Authors