Forum Discussion
Dax query
- Anonymous2 years ago
Hi,vally57
Thank you for your reply.Thank you very much for correcting my misunderstanding of the real data
The following is my understanding of your new requirements
You want to filter the [RATING] column in the Audit table
The screening criteria are as follows:
Take Acqua as an example:
Although only have 23 - and 20-year data, but when the slicer selects other years, you also want measure to display data for the most recent year of the selected year, instead of displaying blank
At this point, even if 21 or 22 years is selected, the data for 2019/20 (the most recent and non-empty count) is displayed.
Since data is available for 23 years (NeedsRefinement), data for 2022/23 is displayed
Here's my code:
test_NeedsRefinement = VAR CurrentDate = MAX('slicer_'[FISCAL_YEAR_ID]) VAR result= CALCULATE( COUNT('Audit'[Name]), FILTER( ALLEXCEPT('Audit',Audit[Name]), Audit[RATING]="Needs Refinement"&& 'Audit'[FISCAL_YEAR_ID] = (CurrentDate) )) VAR max_notblank=CALCULATE(MAX('Audit'[FISCAL_YEAR_ID]),FILTER(ALLSELECTED(Audit),[FISCAL_YEAR_ID]<CurrentDate&&'Audit'[FISCAL_YEAR_ID]<>BLANK())) VAR result1= CALCULATE( COUNT('Audit'[Name]), FILTER( ALLEXCEPT('Audit',Audit[Name]), Audit[RATING]="Needs Refinement"&& 'Audit'[FISCAL_YEAR_ID] =max_notblank )) RETURN IF(result=BLANK(), result1,result)test_NeedsImprovement = VAR CurrentDate = MAX('slicer_'[FISCAL_YEAR_ID]) VAR result= CALCULATE( COUNT('Audit'[Name]), FILTER( ALLEXCEPT('Audit',Audit[Name]), Audit[RATING]="Needs Improvement"&& 'Audit'[FISCAL_YEAR_ID] = (CurrentDate) )) VAR max_notblank=CALCULATE(MAX('Audit'[FISCAL_YEAR_ID]),FILTER(ALLSELECTED(Audit),[FISCAL_YEAR_ID]<CurrentDate&&'Audit'[FISCAL_YEAR_ID]<>BLANK())) VAR result1= CALCULATE( COUNT('Audit'[Name]), FILTER( ALLEXCEPT('Audit',Audit[Name]), Audit[RATING]="Needs Improvement"&& 'Audit'[FISCAL_YEAR_ID]=max_notblank )) RETURN IF(result=BLANK(), result1,result)Below is my test code, in page2
About your non-empty situation because the field filter was written incorrectly "Needs Improvement"
There are two Spaces in the data you provide, not one
Looking forward to your reply
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Anonymous thanks for responding,
Actually, "Needs Improvement" and "Needs Refinement" are not columns; those are values in the column named "Rating." Here, I want the latest non-empty count of the name. For example, if I select 2022/23 from the slicer and do not have "Needs Refinement" or "Needs Improvement" for that particular name, it should get the count of the name from 2021/22.
In the above example, we do not have Acqua data for "Needs Refinement" for the year 2023/24, so we should get the value 2, but I'm getting null. Similarly, if we select 2022/23, we should get 2, but I'm getting 5, which counts the entire date range.
I have added the pbix file
https://www.dropbox.com/scl/fi/5k46fdr2b2kwrkwyd1mwv/test.pbix?rlkey=gs3e020c91pj4mdwtt5kcsv8t&st=rpga040f&dl=0
TIA
Hi,vally57
Thank you for your reply.
Thank you very much for correcting my misunderstanding of the real data
The following is my understanding of your new requirements
You want to filter the [RATING] column in the Audit table
The screening criteria are as follows:
Take Acqua as an example:
Although only have 23 - and 20-year data, but when the slicer selects other years, you also want measure to display data for the most recent year of the selected year, instead of displaying blank
At this point, even if 21 or 22 years is selected, the data for 2019/20 (the most recent and non-empty count) is displayed.
Since data is available for 23 years (NeedsRefinement), data for 2022/23 is displayed
Here's my code:
test_NeedsRefinement =
VAR CurrentDate = MAX('slicer_'[FISCAL_YEAR_ID])
VAR result=
CALCULATE(
COUNT('Audit'[Name]),
FILTER(
ALLEXCEPT('Audit',Audit[Name]),
Audit[RATING]="Needs Refinement"&&
'Audit'[FISCAL_YEAR_ID] = (CurrentDate)
))
VAR max_notblank=CALCULATE(MAX('Audit'[FISCAL_YEAR_ID]),FILTER(ALLSELECTED(Audit),[FISCAL_YEAR_ID]<CurrentDate&&'Audit'[FISCAL_YEAR_ID]<>BLANK()))
VAR result1=
CALCULATE(
COUNT('Audit'[Name]),
FILTER(
ALLEXCEPT('Audit',Audit[Name]),
Audit[RATING]="Needs Refinement"&&
'Audit'[FISCAL_YEAR_ID] =max_notblank
))
RETURN
IF(result=BLANK(),
result1,result)
test_NeedsImprovement =
VAR CurrentDate = MAX('slicer_'[FISCAL_YEAR_ID])
VAR result=
CALCULATE(
COUNT('Audit'[Name]),
FILTER(
ALLEXCEPT('Audit',Audit[Name]),
Audit[RATING]="Needs Improvement"&&
'Audit'[FISCAL_YEAR_ID] = (CurrentDate)
))
VAR max_notblank=CALCULATE(MAX('Audit'[FISCAL_YEAR_ID]),FILTER(ALLSELECTED(Audit),[FISCAL_YEAR_ID]<CurrentDate&&'Audit'[FISCAL_YEAR_ID]<>BLANK()))
VAR result1=
CALCULATE(
COUNT('Audit'[Name]),
FILTER(
ALLEXCEPT('Audit',Audit[Name]),
Audit[RATING]="Needs Improvement"&&
'Audit'[FISCAL_YEAR_ID]=max_notblank
))
RETURN
IF(result=BLANK(),
result1,result)
Below is my test code, in page2
About your non-empty situation because the field filter was written incorrectly "Needs Improvement"
There are two Spaces in the data you provide, not one
Looking forward to your reply
I hope my suggestions give you good ideas, if you have any more questions, please clarify in a follow-up reply.
Best Regards,
Carson Jian,
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
- vally572 years ago
Helper I
AnonymousIt works if there is no relationship between the Audit and Calendar tables. I want a relationship between these tables, but to ignore it, I used the crossfilter function. However, it is still not working. If I manually remove the relationship, I get the expected result, which I do not want.
test_NeedsRefinement =VAR CurrentDate = MAX('Calendar'[Fiscal Year ID])VAR result=CALCULATE(COUNT('Audit'[Name]),FILTER(ALLEXCEPT('Audit','Audit'[Name]),Audit[RATING]="Needs Refinement"&&'Audit'[FISCAL_YEAR_ID] = (CurrentDate)),CROSSFILTER('Calendar'[Date],Audit[PLANNED_START],None))VAR max_notblank=CALCULATE(MAX('Audit'[FISCAL_YEAR_ID]),FILTER(ALLSELECTED(Audit),[FISCAL_YEAR_ID]<CurrentDate&&'Audit'[FISCAL_YEAR_ID]<>BLANK()),CROSSFILTER('Calendar'[Date],Audit[PLANNED_START],None))VAR result1=CALCULATE(COUNT('Audit'[Name]),FILTER(ALLEXCEPT('Audit','Audit'[Name]),Audit[RATING]="Needs Refinement"&&'Audit'[FISCAL_YEAR_ID] =max_notblank),CROSSFILTER('Calendar'[Date],Audit[PLANNED_START],None))RETURNIF(result=BLANK(),- vally572 years ago
Helper I
It works when I use CALCULATE inside another CALCULATE and include the CROSSFILTER function.