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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
Beth_H
Frequent Visitor

Can I refine my data so that I can use less flags

Hi there.

 

I have a table of data I am pulling into PBI desktop that looks similar to the below:

 

placement id  start date  end date
101/01/202401/05/2024
201/01/202401/02/2024
301/02/202401/03/2024
401/02/202401/06/2024
501/02/202431/02/2024
601/01/202431/01/2024
701/03/202401/04/2024
801/03/202401/04/2024
901/03/202401/05/2024
1001/04/200201/07/2024

 

My aim is to create a bar chart that shows when Active Placements against the last 3 months (i.e. A placement is active in that month if the start date is before the last day, and the end date is after the first day). 

 

The issue is that placements will be active over multiple months so I want placements to be counted multiple times.

So far I have only been able to achieve this by adding 3 flag columns onto the table - marking as active or not active in month1, month2, month3 - and then creating a measure to calculate the total count.

 

placement id  start date  end date month1 month2 month3
101/01/2024 01/05/2024 111
201/01/2024 01/02/2024 11 
301/02/2024 01/03/2024 11
401/02/2024 01/06/2024 11
501/02/2024 31/02/2024 1 
601/01/2024 31/01/2024 1  
701/03/2024 01/04/2024  1
801/03/202401/04/2024  1
901/03/202401/05/2024  1
1001/04/200201/07/2024   

 

However, with the amount of other flags I need to consider, this will eventually require the addition of ~50 more columns. Which isn't neat or a great for processing time.

 

Is there a better way to do this? i.e. Can I split my data into a more refined model?

 

Thanks

1 ACCEPTED SOLUTION
Ritaf1983
Super User
Super User

Hi @Beth_H
You can use the linked pattern, it is very simple to use.
Note that the calendar has to be without a relationship with your fact table.

https://blog.finance-bi.com/power-bi-employee-count-by-month/

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

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

View solution in original post

3 REPLIES 3
Sahir_Maharaj
Super User
Super User

Hello @Beth_H,

 

Can you please try this approach:

 

1. Create a date table that covers the range of your data

let
    StartDate = #date(2024, 1, 1),
    EndDate = #date(2024, 12, 31),
    DateList = List.Dates(StartDate, Duration.Days(EndDate - StartDate) + 1, #duration(1, 0, 0, 0)),
    DateTable = Table.FromList(DateList, Splitter.SplitByNothing(), {"Date"}),
    TypeChanged = Table.TransformColumnTypes(DateTable,{{"Date", type date}})
in
    TypeChanged

2. Then, expand each placement record into individual months during which the placement is active. (Ensure the relationship between your date table and your transformed placements table exists)

let
    Source = YourPlacementTable,
    AddMonths = Table.AddColumn(Source, "Months", each {Number.From([start date])..Number.From([end date])}),
    ExpandMonths = Table.ExpandListColumn(AddMonths, "Months"),
    AddYearMonth = Table.AddColumn(ExpandMonths, "YearMonth", each Date.ToText(Date.From([Months]), "yyyy-MM")),
    RemoveUnnecessaryColumns = Table.RemoveColumns(AddYearMonth,{"Months", "start date", "end date"})
in
    RemoveUnnecessaryColumns

3. Finally, create a measure to count the active placements for each month.

Active Placements = 
CALCULATE(
    COUNTROWS(YourTransformedPlacementTable),
    FILTER(
        YourTransformedPlacementTable,
        YourTransformedPlacementTable[YearMonth] = FORMAT(MAX('DateTable'[Date]), "yyyy-MM")
    )
)

Hope this helps!


Did I answer your question? Mark my post as a solution, this will help others!

If my response(s) assisted you in any way, don't forget to drop me a "Kudos" 🙂

Kind Regards,
Sahir Maharaj
Data Scientist | Data Engineer | Data Analyst | AI Engineer
P.S. Want me to build your Power BI solution? (Yes, its FREE!)
➤ Lets connect on LinkedIn: Join my network of 15K+ professionals
➤ Join my free newsletter: Data Driven: From 0 to 100
➤ Website: https://sahirmaharaj.com
➤ Email: sahir@sahirmaharaj.com
➤ Want me to build your Power BI solution? Lets chat about how I can assist!
➤ Join my Medium community of 30K readers! Sharing my knowledge about data science and artificial intelligence
➤ Explore my latest project (350K+ views): Wordlit.net
➤ 100+ FREE Power BI Themes: Download Now
LinkedIn Top Voice in Artificial Intelligence, Data Science and Machine Learning
Ritaf1983
Super User
Super User

Hi @Beth_H
You can use the linked pattern, it is very simple to use.
Note that the calendar has to be without a relationship with your fact table.

https://blog.finance-bi.com/power-bi-employee-count-by-month/

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

 

Regards,
Rita Fainshtein | Microsoft MVP
https://www.linkedin.com/in/rita-fainshtein/
Blog : https://www.madeiradata.com/profile/ritaf/profile

This works perfectly! Thank you.

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.