The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi All,
I require help in getting AVG of the last 5 nonblank values from column B. My table is setup like this:
So, pickup values 3788, 3522, 3604, 2326, 3058 and then avg it.
Can someone help?
Thanks.
Solved! Go to Solution.
I would suggest this measure - a slight modification of the above reply that ensures the top 5 dates are taken from those where B is not blank:
Average of B Over Last 5 Nonblank Dates = VAR Last5Dates = CALCULATETABLE ( TOPN ( 5, VALUES ( YourTable[Date] ), YourTable[Date] ), NOT ISBLANK ( YourTable[B] ) ) RETURN CALCULATE ( AVERAGE ( YourTable[B] ), Last5Dates )
Regards,
Owen
I would suggest this measure - a slight modification of the above reply that ensures the top 5 dates are taken from those where B is not blank:
Average of B Over Last 5 Nonblank Dates = VAR Last5Dates = CALCULATETABLE ( TOPN ( 5, VALUES ( YourTable[Date] ), YourTable[Date] ), NOT ISBLANK ( YourTable[B] ) ) RETURN CALCULATE ( AVERAGE ( YourTable[B] ), Last5Dates )
Regards,
Owen
Hey Ranbeer,
Hello!
The CALCULATE expression allows you to compute values based on certain filters, more info here.
So you would say
CALCULATE(AVERAGE(Column Name),Column Name<>BLANK())
And then in order to select the last 5 measures, you can select the column name in the filters selection > Select ‘Top N’ in the drop-down > switch it to Bottom > enter 5.
Or if you have ranked the column by date, and on the filter, select whichever ones you want by adding another filter to the CALCULATE measure:
CALCULATE(AVERAGE(‘Column Name’),’Column Name’<>BLANK(),’Date’ > (Specific Date))
User | Count |
---|---|
68 | |
63 | |
59 | |
54 | |
28 |
User | Count |
---|---|
181 | |
82 | |
66 | |
47 | |
44 |