March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Dear all,
as DAX beginner I'm currently struggling with my code and I would much appreciate, if somebody could help me to find the right way.
I have two unrelated tables:
All the date related columnes are formatted as date.
In my report I have a Time related slicer for different visuals, where I'm e. g. showing montly results etc.
No I would like to show in another visual only the number of ongoing projects at the end of the selected time period (last month), means all projects which were ongoing at the beginning of the selected period by slicer, but ending earlier than the last month should not be considered. As both tables are unrelated (as I cannot create relation to tart-column and end-column) I'm using the TREATAS-Function.
I tried to create the following measure:
Ongoing_Projects =
CALCULATE (
DISTINCTCOUNT( FACT_Project[Project_ID]),
FILTER
(FACT_Project[Project_end] > TREATAS ( VALUES ( DIM_calendar[Date] ), FACT_Project[end])
&& FACT_Project[start] < TREATAS ( VALUES ( DIM_calender[Date] ), FACT_Project[von]))
)
)
which don't work 😥 I think the reason is, that I didn't adress the start and the end of the slicer selection correctly, but no idea how to solve this issue.
Can anybody help me ? Thanks a lot in advance for all efforts
Bärbel
Solved! Go to Solution.
Try
Ongoing projects =
VAR MaxDate =
MAX ( 'Dim_calendar'[Date] )
VAR Result =
CALCULATE (
COUNTROWS ( 'FACT_project' ),
'FACT_project'[start date] <= MaxDate
&& (
ISBLANK ( 'FACT_project'[End date] )
|| 'FACT_project'[End date] > MaxDate
)
)
RETURN
Result
This assumes that there is only 1 entry in the fact table for each project. If there might be multiple entries then you can replace the COUNTROWS with DISTINCTCOUNT( FACT_Project[Project_ID])
WoW 😃 you made my day, thanks so much, it works 🤣
In any case you would have another second for me to understand - why it works without a relationship between
A relationship with the date table would only help to capture events that happened on a specific date, or within a range of specified dates. Here you are wanting to check whether one date was before the given date range and one was after, so a relationship wouldn't help.
Thanks - its a helpfull info for me for similiar issues
Try
Ongoing projects =
VAR MaxDate =
MAX ( 'Dim_calendar'[Date] )
VAR Result =
CALCULATE (
COUNTROWS ( 'FACT_project' ),
'FACT_project'[start date] <= MaxDate
&& (
ISBLANK ( 'FACT_project'[End date] )
|| 'FACT_project'[End date] > MaxDate
)
)
RETURN
Result
This assumes that there is only 1 entry in the fact table for each project. If there might be multiple entries then you can replace the COUNTROWS with DISTINCTCOUNT( FACT_Project[Project_ID])
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
25 | |
18 | |
15 | |
9 | |
8 |
User | Count |
---|---|
37 | |
32 | |
16 | |
16 | |
12 |