Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreWe've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now
Dear Community,
I am having an issue which I believe it might be something common, since I already found a lot of similar topics searching for this topic through the community. But sadly, I couldn't find a solution that fits to my problem.
I have two Data Tables and two Head Tables:
(please see attached xlsx to see a sample of the data used)
https://drive.google.com/file/d/1CGfA3yFGci3GuOx7bkFi912pHPW08SGE/view?usp=sharing
On Power BI I want the user to be able to select an specific Site and Month, and then he should see:
My Problem is:
A solution I tried:
VAR xFirstPeriod= CALCULATE(FIRSTDATE(Calender[Date].[Date]),ALLSELECTED(Calender))
VAR xLastPeriod= LASTDATE(Calender[Date].[Date])
VAR xStartDate = CALCULATE(MIN(Incidents[Start Date]))
VAR xFinishDate= CALCULATE(MIN(Incidents[Finish Date])
)
RETURN
IF(
AND(
xStartDate <=xLastPeriod,
OR(ISBLANK(xFinishDate), xFinishDate >= xFirstPeriod)
),
"Active",
"Inactive"
)
The idea was to put that measure in the Incidents Table and filter only the "Active". I tried changing it with ALL, ALLSELECTED, FIRSTDATE, etc. but not a single variation I tried worked.
Can someone guide me through how should I Proceed in this case?
Extra:
I would also like to make a line chart: on X axis, the Days and on Y Axis the count of Active Incidents
For example: If I have the two following Incidents:
Inc1 - Start Date 01/03/20 - Finish Date 04/03/20
Inc2 - Start Date 03/03/20 - Finish Date 05/03/20
The chart would count 2 for 3rd and 4th, and 1 for 1st, 2nd and 5th of march.
Solved! Go to Solution.
Since the incidents can span multiple dates and you only have one row for each incident, creating a relationship to the calendar table isn't going to work in a very useful way. Note that trying to put a calculated column with "active"/"inactive" on the incident table is doomed to failure since a calculated column cannot read slicer values since it is only evaluated once per data load (not in response to user interactions).
A measure can read slicer values, so you can write one to count incidents on a particular date (to use in your chart) along these lines:
IncidentCountOnDate =
VAR xDate = SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
COUNTROWS (
FILTER (
Incidents,
Incidents[Start Date] <= xDate
&& Incidents[Finish Date] >= xDate
)
)
Filtering incidents for a month is more difficult than for a day but your Check_If_Active seems to be on the right track (as a measure, not a calculated column) if it's filtering a visual.
Since the incidents can span multiple dates and you only have one row for each incident, creating a relationship to the calendar table isn't going to work in a very useful way. Note that trying to put a calculated column with "active"/"inactive" on the incident table is doomed to failure since a calculated column cannot read slicer values since it is only evaluated once per data load (not in response to user interactions).
A measure can read slicer values, so you can write one to count incidents on a particular date (to use in your chart) along these lines:
IncidentCountOnDate =
VAR xDate = SELECTEDVALUE ( 'Calendar'[Date] )
RETURN
COUNTROWS (
FILTER (
Incidents,
Incidents[Start Date] <= xDate
&& Incidents[Finish Date] >= xDate
)
)
Filtering incidents for a month is more difficult than for a day but your Check_If_Active seems to be on the right track (as a measure, not a calculated column) if it's filtering a visual.
Thank you for your answer Alexis!
The active count measure worked, thank you!
At first instance, it wasn't working. Later on I realized I had another table with "both" relation which was the reason for the measure to not be working....
The measure I was trying to create is not even needed anymore:
I just add on "Filters for this visual" this measure you suggested to be greater then 0, and it automatically filters only the active ones in the selected period.
PS: I did a small change in the measure you sent to englobe a bigger period (like selecting multiple months)
That's how the measure looked like in the end:
3.0 Active Incidents =
VAR xBeginDate = (FIRSTDATE( 'Calender'[Date] ))
VAR xEndDate = (LASTDATE( 'Calender'[Date] ))
VAR xCount =
COUNTROWS (
FILTER (
Incidents,
Incidents[Start Date] <= xEndDate
&& (Incidents[Finish Date] >= xBeginDate || ISBLANK(Incidents[Finish Date]))
)
)
RETURN
If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.
A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.
Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.
| User | Count |
|---|---|
| 51 | |
| 37 | |
| 35 | |
| 19 | |
| 17 |
| User | Count |
|---|---|
| 70 | |
| 64 | |
| 39 | |
| 33 | |
| 23 |