Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
I calculate an average value, but not all rows are filled in the original data. These I want to filter this and only return rows containing data in all columns.
Here the data after the caluculation of the average:
I can achieve this by setting a filter in the "filter pane" in the Desktop App.
But, how can I do this in DAX?
Here my code:
LocalCountOfAccicentsAvg =
VAR Known =
FILTER (
SELECTCOLUMNS (
ALLSELECTED ('Date'[Date]),
"Known[X]", 'Date'[Date],
"Known[Y]", CALCULATE(sum(KpiData[LocalCountOfAccidents]))
),
AND (
NOT ( ISBLANK ( Known[X] ) ),
NOT ( ISBLANK ( Known[Y] ) )
)
)
VAR Count_Items =
COUNTROWS ( Known )
VAR Sum_X = SUMX ( Known, Known[X] )
VAR Sum_X2 = SUMX ( Known, Known[X] ^ 2 )
VAR Sum_Y = SUMX ( Known, Known[Y] )
VAR Sum_XY = SUMX ( Known, Known[X] * Known[Y] )
VAR Average_X = AVERAGEX ( Known, Known[X] )
VAR Average_Y = AVERAGEX ( Known, Known[Y] )
VAR Slope = DIVIDE (
Count_Items * Sum_XY - Sum_X * Sum_Y,
Count_Items * Sum_X2 - Sum_X ^ 2
)
VAR Intercept = Average_Y - Slope * Average_X
VAR AllData = SUMX ( DISTINCT ( 'Date'[Date] ),
Intercept + Slope * 'Date'[Date])
RETURN AllData
Thanks!
I think the only issue with your code is not having the [ ] around your table names in the ISBLANKs. I would not use [] in your virtual column names, to simplify things. I would just use "KnownY" and "KnownX" when naming your columns in the SELECTCOLUMNS.
Regards,
Pat
To learn more about Power BI, follow me on Twitter or subscribe on YouTube.
This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.
Check out the June 2025 Power BI update to learn about new features.
User | Count |
---|---|
14 | |
10 | |
10 | |
9 | |
9 |
User | Count |
---|---|
20 | |
13 | |
12 | |
11 | |
8 |