Forum Discussion
Diego-mx
7 years agoAdvocate I
Comparing to Filtered Table
I have one table with business locations: location_name, open_date, close_date I have a calendar table that gets filtered via a slicer. I want to count how many locations were open in a given win...
- 7 years ago
Hi Diego-mx
"Events in progress" is the generic name for the type of measure you are wanting to create here. From your description, I take it that you want to count Locations that were open on at least one day in the filtered period.
- First of all, if we just try to fix your current measure, there is a slight logical error: we actually want Locations that open on or before the Max filtered date, and close on or after the Min filtered date. Also, just to be safe I suggest using DISTINCTCOUNT, though it won't matter if Locations appear at most once. A corrected measure would be:
OpenLocations = CALCULATE ( DISTINCTCOUNT ( Locations[location_name] ), FILTER ( Locations, Locations[open_date] <= MAX ( 'Calendar'[a_date] ) && ( Locations[close_date] >= MIN ( 'Calendar'[a_date] ) || ISBLANK ( Locations[close_date] ) ) ) ) - The above measure however may not perform well in a large model, as you are filtering the entire Locations table.
Based on this paper on SQLBI (page 27) a better-performing measure would be:OpenLocations v2 = VAR SelectedDates = VALUES ( 'Calendar'[a_date] ) RETURN CALCULATE ( DISTINCTCOUNT ( Locations[location_name] ), GENERATE ( SUMMARIZE ( Locations, Locations[open_date], Locations[close_date] ), INTERSECT ( DATESBETWEEN ( 'Calendar'[a_date], Locations[open_date], Locations[close_date] ), SelectedDates ) ) ) - Another option that you may want to consider is restructuring your Locations table according to this article on SQLBI, so that there is a row per date that each Location is open, with a single date column.
Regards,
Owen
- First of all, if we just try to fix your current measure, there is a slight logical error: we actually want Locations that open on or before the Max filtered date, and close on or after the Min filtered date. Also, just to be safe I suggest using DISTINCTCOUNT, though it won't matter if Locations appear at most once. A corrected measure would be:
Ashish_Mathur
7 years agoSuper User
Hi,
This isn't a difficult problem to solve. Share some data.
Diego-mx
7 years agoAdvocate I
My dashboards are very convoluted already. For my next post, I'll try to come up with a toy dataset.
This one got solved alright.
Thanks though.