Don't miss your chance to take the Fabric Data Engineer (DP-700) exam on us!
Learn moreThe FabCon + SQLCon recap series starts April 14th at 8am Pacific. If you’re tracking where AI is going inside Fabric, this first session is a can't miss. Register now
Hi all! I have a very simple model with 2 tables - one fact with cases and history and one date dimension in SSAS. I need a measure to count open cases at the start of each contextualized period. So for example:
| Date | Open cases start of day |
| 01-01-2021 | 13400 |
| 02-02-2021 | 13230 |
| 03-02-2021 | 13300 |
Now, I can achieve this PER day in MSSQL with the following query:
DECLARE @FilterDate AS DATE;
SET @FilterDate = '2021-01-01'
Select COUNT(*)
FROM FactTable
WHERE TaskCompleted IS NULL
AND IsDeleted = 0
AND DW_ValidFrom < @FilterDate
AND DW_ValidTo >= @FilterDate
In SQL I can create a function that reiterates all of the dates needed for my date variable so I would get the table above. In my tabular model I have a 1:* relationship from DimDate to FactCases on DateKey to DW_ValidFrom
Could someone help me translate this seemingly easy query to a DAX statement?
Solved! Go to Solution.
@johnsmith92 , if you do not have an active join between two tables then you do not need a crossfilter. Make both join inactive
Hi @johnsmith92 ,
Try:
Count=
var _date=IF(SELECTEDVALUE('Date'[date])=BLANK(),DATE(2021,1,1),SELECTEDVALUE('Date'[date]))
Return
CALCULATE(COUNTROWS('FactTable'),FILTER(ALL('FactTable'),'FactTable'[TaskCompleted]=BLANK()&&'FactTable'[IsDeleted]=0&& 'FactTable'[DW_ValidFrom]<_date && 'FactTable'[DW_ValidTo]>=_date))
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
Hi @amitchandak. Thanks for your prompt reply! Unfortunately we are running SQL Server 2014, so I cannot use the CROSSFILTER function. Is there another way to write it?
@johnsmith92 , if you do not have an active join between two tables then you do not need a crossfilter. Make both join inactive
I did as you suggested, but now I'm getting some wild results that are not expected.
Hi @johnsmith92 ,
Is your issue solved now?
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
Yes, using inactive relations between tables does the trick. 🙂
Hi @johnsmith92 ,
Great!
Best Regards,
Kelly
Did I answer your question? Mark my reply as a solution!
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 |
|---|---|
| 53 | |
| 40 | |
| 38 | |
| 19 | |
| 18 |
| User | Count |
|---|---|
| 70 | |
| 69 | |
| 34 | |
| 33 | |
| 30 |