Forum Discussion
Running Total Issue in Power BI
Hi,
I have one table where I have worker start date and end date. This table has unique values only. So for each worker there is one start date and one end date.
The start date of the worker is connected to the Calender Table.
I am trying to show count of workers such that eg.
if Italy had 3 workers in Jan and one worker was added in April then the output should be like
Jan 3
Feb 3
March 3
April 4
I am using below formula to achieve this
VAR CurrentDate = MAX('Calender'[Date])
RETURN
CALCULATE(
DISTINCTCOUNT('Worker Table[ID]),
'Worker Table'[GEOGRAPHY]
IN { "Poland", "Spain", "France", "Australia", "Italy" },
'Worker Table'[Active/Ended] = "Active",
FILTER(
ALLSELECTED('Calender'[Date]),
'Calender'[Date] <= CurrentDate
)
)
but this is not showing running total, It is showing me count directly in the month the contractor was added.
Result was
Jan 3
Feb 0
March 0
April 4
How to solve this, is this because we have distinct start dates in the Worker table?
8 Replies
- AnonymousNot applicable
Hi Revati25,
Thank you for reaching out to the Microsoft Fabric Forum Community, and special thanks to Natarajan_M , Jihwan_Kim and cengizhanarslan for prompt and helpful responses.
Just following up to see if the Response provided by community members were helpful in addressing the issue. if the issue still persists Feel free to reach out if you need any further clarification or assistance.
Best regards,
Prasanna Kumar- Revati25Advocate I
I have posted the result I got from this approch
- cengizhanarslanSuper User
Please try the measure below:
Measure = VAR CurrentDate = MAX ( 'Calendar'[Date] ) RETURN CALCULATE ( DISTINCTCOUNT ( 'Worker Table'[ID] ), REMOVEFILTERS ( 'Calendar' ), -- important: removes the StartDate relationship filtering 'Worker Table'[GEOGRAPHY] IN { "Poland", "Spain", "France", "Australia", "Italy" }, FILTER ( ALL ( 'Worker Table' ), 'Worker Table'[StartDate] <= CurrentDate && ( ISBLANK ( 'Worker Table'[EndDate] ) || 'Worker Table'[EndDate] > CurrentDate ) ) ) - Jihwan_KimSuper User
Hi,
Please correct me if my sample pbix file is not similar as what you have, but it seems like your dax measure works.
Please check the below and the attached pbix file.
Count of workers: = VAR CurrentDate = MAX ( 'Calendar'[Date] ) RETURN CALCULATE ( DISTINCTCOUNT ( 'Worker Table'[ID] ), 'Worker Table'[GEOGRAPHY] IN { "Poland", "Spain", "France", "Australia", "Italy" }, 'Worker Table'[Active/Ended] = "Active", FILTER ( ALLSELECTED ( 'Calendar'[Date] ), 'Calendar'[Date] <= CurrentDate ) ) - Natarajan_MSuper User
Hi Revati25 , I was able to recreate your scenario I created 2 measures Base measure and final measure
Headcount Base =VAR CurrentDate = MAX('Calendar'[Date])VAR PeriodStart = MIN('Calendar'[Date])RETURNCALCULATE(DISTINCTCOUNT('Fact Table'[ID]), -- Counts unique employees'Fact Table'[Start] <= CurrentDate,OR(ISBLANK('Fact Table'[End]),'Fact Table'[End] >= PeriodStart))Headcount Final Measure =VAR CurrentDate = MAX('Calendar'[Date])RETURNCALCULATE(-- 1. Call your existing base measure[Headcount Base],-- 2. Expand the window to include all dates up to the current dateFILTER(ALL('Calendar'),'Calendar'[Date] <= CurrentDate))
Italy:
Italy :
Data :
Model :
Thanks
If this response was helpful in any way, I’d gladly accept a kudo.
Please mark it as the correct solution. It helps other community members find their way faster. - Revati25Advocate I
I have data with start date and end date as well, I want to show employee active only till its end date is not ended.
Eg, 1st row
Start Date is September 2021 and End Date February 2024. So this employee should be active from
2021 September to February 2024.
Relationship is between - > Start Date and Calendar Table - AnonymousNot applicable
Hi Revati25,
If the issue still persists, we kindly request you to share the sample data in a workable format such as text, an Excel file, or a PBIX file with sample data instead of screenshots. Additionally, please include the expected output. This will enable us to assist you more effectively.
Regards,
Prasanna Kumar - AnonymousNot applicable
Hi @Revati25,
Apologies for the delayed response.
If the issue still persists, we kindly request you to share the sample data in a workable format such as text, an Excel file, or a PBIX file with sample data instead of screenshots. Additionally, please include the expected output. This will enable us to assist you more effectively.
Regards,
Prasanna Kumar