March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
Hi,
we need count of records for a Table which belongs to last 03 quarters; I´m trying to using the code below but shows an error.
Can someone help me?
---
Measure01 = CALCULATE(
COUNTROWS('Table1'),
FILTER('Table1','Table1'[Data de propositura].[Quarter]=-3))
---
Solved! Go to Solution.
Since I was unable to find some help to it, I was able to get results using another way as described below:
1) Add 02 'Custom Collumn' to the table with help of 'PowerQuery M';
A) First custom collumn was to find if the 'DateIsInCurrentQuarter' (=Date.IsInCurrentQuarter ([DateField]));
B) Second custom collumn was to find if the 'DateIsInPreviousQuarter' (=Date.IsInPreviousNQuarters(Date.AddQuarters([DateField], -1), 2));
2) Create a Measure with filters to ignore records in current quarter and also filter to obtain records where 'previous quarter' is true.
Take a look my DAX Measure:
######################
Since I was unable to find some help to it, I was able to get results using another way as described below:
1) Add 02 'Custom Collumn' to the table with help of 'PowerQuery M';
A) First custom collumn was to find if the 'DateIsInCurrentQuarter' (=Date.IsInCurrentQuarter ([DateField]));
B) Second custom collumn was to find if the 'DateIsInPreviousQuarter' (=Date.IsInPreviousNQuarters(Date.AddQuarters([DateField], -1), 2));
2) Create a Measure with filters to ignore records in current quarter and also filter to obtain records where 'previous quarter' is true.
Take a look my DAX Measure:
######################
Hi @jr3151006
It seems you only have one table in the model. You can also try the following measure without adding new columns. It uses some Date functions. Date and time functions (DAX) - DAX | Microsoft Docs
MeasurePreviousQuarter =
VAR _currentQuarterStart =
DATE ( YEAR ( TODAY () ), QUARTER ( TODAY () ) * 3 - 2, 1 )
VAR _previous3QuarterStart =
EOMONTH ( _currentQuarterStart, -10 ) + 1
RETURN
COUNTROWS (
FILTER (
'Table1',
'Table1'[Date] >= _previous3QuarterStart
&& 'Table1'[Date] < _currentQuarterStart
)
)
Additionally, DATEADD is a Time Intelligence function. To use it, it is recommended to have a Date table in the model. Time intelligence functions (DAX) - DAX | Microsoft Docs
Best Regards,
Community Support Team _ Jing
If this post helps, please Accept it as Solution to help other members find it.
Hi v-jingzhang,
I'll test this and ping back here in few hours. Tks for your help.
I did some change and now the error is:
"MdxScript(Model) (21, 51) Calculation error in measure 'Table1'[Measure067]: Cannot convert value 'Qtr 1' of type Text to type Number."
----
My Current DAX Measure
###################
Measure01 = CALCULATE(
COUNTROWS('Table1'),
FILTER('Table1','Table1'[DateField]='Table1'[DateField].[Quarter]-3))
@jr3151006 Try the below DAX:
Measure = CALCULATE(COUNTROWS(Table1),DATEADD(Datecolumn,-3,QUARTER))
Hi Tahreem24,
tks for quick reply.
Almost there....
The result expected (for this test) was '0' since the dates on table are '08/07/2022', '09/07/2016' and '27/11/2020'. Pls, don't get me wrong but I realize that this code just ignores the current the current year.
Maybe we need to adjust the DAX to also consider the current year + quarter in the calc.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
129 | |
90 | |
75 | |
58 | |
53 |
User | Count |
---|---|
200 | |
104 | |
101 | |
67 | |
55 |