Forum Discussion
DateSpan
- Anonymous1 year ago
Hi nchamilton2 ,
You're correct that directly joining the DateSpan table to the FactTable introduces a many-to-many relationship, which Power BI doesn’t handle as cleanly as other analytics tools. To support your scenario generating all dates between each phase’s estimated start and end, while avoiding many-to-many joins the recommended approach is to reshape the model slightly by introducing Phases as a bridge table.
First create a dynamic DateSpan table in Power Query that expands each phase into one row per date using this code:
let Source = Phases, ChangedTypes = Table.TransformColumns(Source, { {"EstStartDate", each Date.FromText(_, "en-US"), type date}, {"EstEndDate", each Date.FromText(_, "en-US"), type date} }), AddDateList = Table.AddColumn(ChangedTypes, "Date", each List.Dates([EstStartDate], Duration.Days([EstEndDate] - [EstStartDate]) + 1, #duration(1,0,0,0))), ExpandedDates = Table.ExpandListColumn(AddDateList, "Date"), SelectedColumns = Table.SelectColumns(ExpandedDates, {"PhaseId", "Date", "PhaseName"}) in SelectedColumnsAdjust the relationships in the model:
- DynamicDateSpan[PhaseId] → Phases[PhaseId] (One-to-many)
- FactTable[PhaseId] → Phases[PhaseId] (Many-to-one)
- FactTable[ProjectID] → Projects[ProjectID] (Many-to-one)
Use Phases as the central bridge. This lets both the fact table and the generated date list connect indirectly, avoiding many-to-many conflicts.
To show ProjectTitle, you can either create a measure like:
ProjectTitle := CALCULATE ( SELECTEDVALUE ( Projects[ProjectTitle] ), TREATAS ( VALUES ( DynamicDateSpan[PhaseId] ), FactTable[PhaseId] ), FactTable )Or build a calculated table if you need a flattened structure.
This setup should meet your needs: dynamically showing each phase across all active dates, with project info, while maintaining a clean and performant model.
hope this helps, please feel free to reach out for further issue.
Thank you.
I do not see the many to many thing, which columns connected would result in a many to many in your view?
To what I see, connect the calendar to either the start or the end dat of the project and that's it
Or maybe in your DateSpan the dates would repeat as you have mutiple Phaseid?
In that case please consider for the calendar only the colum dates (and months etc), but nothing else
So data model
Connect The date table to Fact
Connect the Phases table to Fact
Connect the Project Table to fact
Connect the calendar (without any ohase column in it) to Fact
If this helped, please consider giving kudos and mark as a solution
me in replies or I'll lose your thread
consider voting this Power BI idea
Francesco Bergamaschi
MBA, M.Eng, M.Econ, Professor of BI
Thanks for the reply. I'm not able to connect the date table to the fact table because it generates a many to many if I connect it via the phaseid. If I connect via the date from Datespan to Phasestartdate in fact I lose the ability to utilize the spanned dates. I want to be able to return a date for each day for each phase between phasestart and phaseenddate.
Thanks.
- FBergamaschi1 year agoSuper User
The date table needs to be connected to the fact table via the date column (and the pahse needs to be eliminated from the date table, that is a date table), the rest will be done via DAX
- nchamilton21 year agoFrequent Visitor
Can you please point me in the right direction of what the next steps are in DAX please?