Power BI is turning 10, and we’re marking the occasion with a special community challenge. Use your creativity to tell a story, uncover trends, or highlight something unexpected.
Get startedJoin us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.
My title above as a web search does not provide any clues. Normally this means that I am doing something out of the ordinary or brain-dead :}
But still, such a simple request. How does one ?
This SO post was the closest I found to what I am seeking and they drew a blank from the inter-net-o-sphere too :}
Reference Page Filter in DAX expression - powerbi
I have been playing with ALLSELECTED and FILTERS so far.
Code below. _CurrentScore is based off dashboard 'filters' values and works. Great.
_PreviousScore says give me the prior quarter period.
Then I am going to do a comparision
VAR _CurrentScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _PreviousScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
IF ( 'Project Progress List'[Quarter] <> "Q1",
'Project Progress List'[Financial Year], -- no change
LEFT ( 'Project Progress List'[Financial Year], 4 ) - 1 & "-" &
RIGHT ( 'Project Progress List'[Financial Year], 2 ) - 1 -- previous FY
),
SWITCH ( -- to previous quarter
'Project Progress List'[Quarter],
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
)
)
)
128 records, 64 of each quarter Q3 and Q4. From the ParentID and ChildID's we see sets of two corresponding records. CPS column in our cutdown example is always Yes so can be ignored.
current to previous quarter.data.csv
Related code transposition to the above test data file
EVALUATE
--Score Change Flag =
VAR _PMID = { MIN ( 'Test'[ParentId] ) }
VAR _PPLID = { MIN ( 'Test'[ChildId] ) }
VAR _FY = { MIN ( 'Test'[FY] ) }
VAR _Qtr = { MIN ( 'Test'[Qtr] ) }
VAR CPS = { MIN ( 'Test'[CPS] ) }
VAR _FYPrev = {
IF ( _Qtr <> "Q1",
_FY, -- no change
LEFT(_FY,4)-1 & "-" & RIGHT(_FY,2)-1 -- previous FY
) }
VAR _QtrPrev = {
SWITCH ( -- to previous quarter
_Qtr,
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
) }
VAR _CurrentScore =
CALCULATE (
MIN ( 'Test'[Score] ),
ALLSELECTED (
'Test'[CPS],
'Test'[FY],
'Test'[Qtr]
)
)
VAR _PreviousScore =
CALCULATE (
MIN ( 'Test'[Score] ),
ALLSELECTED (
'Test'[CPS],
IF ( 'Test'[Qtr] <> "Q1",
'Test'[FY], -- no change
LEFT ( 'Test'[FY], 4 ) - 1 & "-" &
RIGHT ( 'Test'[FY], 2 ) - 1 -- previous FY
),
SWITCH ( -- to previous quarter
'Test'[Qtr],
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
)
)
)
VAR _CurrentRowSet =
CALCULATETABLE (
SELECTCOLUMNS (
'Test',
"PMID", 'Test'[ParentId],
"PPLID", 'Test'[ChildId],
"FY", 'Test'[FY],
"Qtr", 'Test'[Qtr],
"Cost Score", 'Test'[Score],
"CPS", 'Test'[CPS]
),
'Test'[CPS] = CPS,
'Test'[FY] = _FY,
'Test'[Qtr] = _Qtr
)
VAR _PreviousRowSet =
CALCULATETABLE (
SELECTCOLUMNS (
'Test',
"PMID", 'Test'[ParentId],
"PPLID", 'Test'[ChildId],
"FY", 'Test'[FY],
"Qtr", 'Test'[Qtr],
"Cost Score", 'Test'[Score],
"CPS", 'Test'[CPS]
),
'Test'[CPS] = CPS,
'Test'[FY] = _FYPrev,
'Test'[Qtr] = _QtrPrev
)
--VAR _Test = { _FYPrev &" "& _QtrPrev }
--VAR _Test = _CurrentRowSet
--VAR _Test = _PreviousRowSet
VAR _Test = { _CurrentScore }
/*
VAR _Test = { _PMID &" "& _PPLID &" "& UNICHAR(10) &
_FY &" "& _Qtr &" "& CPS & UNICHAR(10) &
_FYPrev &" "& _QtrPrev
}
*/
RETURN
_Test
Solved! Go to Solution.
For prosperity the final solution.
Associated test visual
Filters being CPS = "Yes", FY = "2023-24" and Quarter = "Q4 or Q3"
Initiative Cost, Current Score =
VAR _CurrentScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _CurrentScore }
RETURN
_Return
Initiative Cost, Previous Score =
/*
Summary boolean flag to denote whether cost status change from previous quarter
Details + comparisons only on adjoining quarters, we are only moving forwards in time sequence Q1 Q2 Q3 Q4
- but Q4 to Q1 will be a different FY ie yyyy-yy Q4 Vs yyyy+1-yy+1 Q1
Notes + 'Cost' now supercedes 'FTL' (Financial Traffic Light) terminology
+ warning EARLIER usage; syntax and logic can only be checked via pbi desktop and not daxstudio
History 202407 gt build
*/
-- obtain the related rowset for the master record
VAR _PMID =
CALCULATE (
MAX ( 'Project Progress List'[PjMaster IDId] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
/* hack does not work in this context hence the configuration driven references
VAR _FY = { MIN ( 'Project Progress List'[Initiative Cost, filters, FY] ) } // hack
VAR _Qtr = { MIN ( 'Project Progress List'[Initiative Cost, filters, Qtr] ) } // hack
VAR _CPS = { MIN ( 'Project Progress List'[Initiative Cost, filters, CPS] ) } // hack
*/
-- just hardcode from Dates Reference table
VAR _FY = { MIN ( 'x Reference Dates (static)'[FINANCIALYEAR_YYYY_YY] ) } // hardcoded reference
VAR _Qtr = { MIN ( 'x Reference Dates (static)'[THISQUARTER] ) } // hardcoded reference
VAR _CPS = "Yes"
VAR _FYPrev = {
IF ( _Qtr <> "Q1",
_FY, -- no change
LEFT(_FY,4)-1 & "-" & RIGHT(_FY,2)-1 -- previous FY
) }
VAR _QtrPrev = {
SWITCH ( -- to previous quarter
_Qtr,
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
) }
VAR _PreviousScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
'Project Progress List'[PjMaster IDId] = _PMID,
-- we are returning all ppl id rows for the pmid
'Project Progress List'[Corporate Plan Signa] = _CPS,
'Project Progress List'[Financial Year] = _FYPrev,
'Project Progress List'[Quarter] = _QtrPrev
)
VAR _Return = { _PreviousScore }
RETURN
_Return
Initiative Cost, Previous Score 2 =
-- fill in 'current' quarter row with Previous Score
-- see further notes [Initiative Cost, Prevous Score]
-- obtain the related rowset for the master record
VAR _PMID =
CALCULATE (
MAX ( 'Project Progress List'[PjMaster IDId] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
-- find the previous score for the related rowset found in the previous step ([Initiative Cost, Prevous Score])
VAR _PreviousScore2 =
CALCULATE (
MAX ( 'Project Progress List'[Initiative Cost, Previous Score] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
VAR _Return = { _PreviousScore2 }
RETURN
_Return
Initiative Cost, Outcome Trend Indicator =
-- ignore Not Reported
IF ('Project Progress List'[Initiative Cost, Current Score] = 0 ||
'Project Progress List'[Initiative Cost, Previous Score 2] = 0,
"NA",
IF ('Project Progress List'[Initiative Cost, Current Score] >
'Project Progress List'[Initiative Cost, Previous Score 2],
UNICHAR ( 9650 ), -- improving trend 'triangle'
IF ('Project Progress List'[Initiative Cost, Current Score] <
'Project Progress List'[Initiative Cost, Previous Score 2],
UNICHAR ( 9660 ), -- downward trend 'upside down triangle'
UNICHAR ( 8210 ) -- consistent trend 'dash'
)
)
)
For prosperity the final solution.
Associated test visual
Filters being CPS = "Yes", FY = "2023-24" and Quarter = "Q4 or Q3"
Initiative Cost, Current Score =
VAR _CurrentScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _CurrentScore }
RETURN
_Return
Initiative Cost, Previous Score =
/*
Summary boolean flag to denote whether cost status change from previous quarter
Details + comparisons only on adjoining quarters, we are only moving forwards in time sequence Q1 Q2 Q3 Q4
- but Q4 to Q1 will be a different FY ie yyyy-yy Q4 Vs yyyy+1-yy+1 Q1
Notes + 'Cost' now supercedes 'FTL' (Financial Traffic Light) terminology
+ warning EARLIER usage; syntax and logic can only be checked via pbi desktop and not daxstudio
History 202407 gt build
*/
-- obtain the related rowset for the master record
VAR _PMID =
CALCULATE (
MAX ( 'Project Progress List'[PjMaster IDId] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
/* hack does not work in this context hence the configuration driven references
VAR _FY = { MIN ( 'Project Progress List'[Initiative Cost, filters, FY] ) } // hack
VAR _Qtr = { MIN ( 'Project Progress List'[Initiative Cost, filters, Qtr] ) } // hack
VAR _CPS = { MIN ( 'Project Progress List'[Initiative Cost, filters, CPS] ) } // hack
*/
-- just hardcode from Dates Reference table
VAR _FY = { MIN ( 'x Reference Dates (static)'[FINANCIALYEAR_YYYY_YY] ) } // hardcoded reference
VAR _Qtr = { MIN ( 'x Reference Dates (static)'[THISQUARTER] ) } // hardcoded reference
VAR _CPS = "Yes"
VAR _FYPrev = {
IF ( _Qtr <> "Q1",
_FY, -- no change
LEFT(_FY,4)-1 & "-" & RIGHT(_FY,2)-1 -- previous FY
) }
VAR _QtrPrev = {
SWITCH ( -- to previous quarter
_Qtr,
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
) }
VAR _PreviousScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
'Project Progress List'[PjMaster IDId] = _PMID,
-- we are returning all ppl id rows for the pmid
'Project Progress List'[Corporate Plan Signa] = _CPS,
'Project Progress List'[Financial Year] = _FYPrev,
'Project Progress List'[Quarter] = _QtrPrev
)
VAR _Return = { _PreviousScore }
RETURN
_Return
Initiative Cost, Previous Score 2 =
-- fill in 'current' quarter row with Previous Score
-- see further notes [Initiative Cost, Prevous Score]
-- obtain the related rowset for the master record
VAR _PMID =
CALCULATE (
MAX ( 'Project Progress List'[PjMaster IDId] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
-- find the previous score for the related rowset found in the previous step ([Initiative Cost, Prevous Score])
VAR _PreviousScore2 =
CALCULATE (
MAX ( 'Project Progress List'[Initiative Cost, Previous Score] ),
FILTER (
ALL ('Project Progress List'),
'Project Progress List'[PjMaster IDId] = EARLIER ( 'Project Progress List'[PjMaster IDId] )
)
)
VAR _Return = { _PreviousScore2 }
RETURN
_Return
Initiative Cost, Outcome Trend Indicator =
-- ignore Not Reported
IF ('Project Progress List'[Initiative Cost, Current Score] = 0 ||
'Project Progress List'[Initiative Cost, Previous Score 2] = 0,
"NA",
IF ('Project Progress List'[Initiative Cost, Current Score] >
'Project Progress List'[Initiative Cost, Previous Score 2],
UNICHAR ( 9650 ), -- improving trend 'triangle'
IF ('Project Progress List'[Initiative Cost, Current Score] <
'Project Progress List'[Initiative Cost, Previous Score 2],
UNICHAR ( 9660 ), -- downward trend 'upside down triangle'
UNICHAR ( 8210 ) -- consistent trend 'dash'
)
)
)
Test visual in master id order. We can clearly see the quarter record pairs.
Filters pane showing CPS (all Yes), Financial Year and Quarter filter values
Calculated column code
EVALUATE
--Initiative Cost, filters, CPS =
VAR _PMID = { MIN ( 'Project Progress List'[PjMaster IDId] ) }
VAR _PPLID = { MIN ( 'Project Progress List'[Id] ) }
VAR _FY = { MIN ( 'Project Progress List'[Financial Year] ) }
VAR _Qtr = { MIN ( 'Project Progress List'[Quarter] ) }
VAR _CPS = { MIN ( 'Project Progress List'[Corporate Plan Signa] ) }
-- hack to get Filters pane, Filters on this page/Filters on all pages specific filter value
VAR _CPS_hack =
CALCULATE (
MIN ( 'Project Progress List'[Corporate Plan Signa] ), // hack
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _CPS_hack }
RETURN
_Return
EVALUATE
--Initiative Cost, filters, FY =
VAR _PMID = { MIN ( 'Project Progress List'[PjMaster IDId] ) }
VAR _PPLID = { MIN ( 'Project Progress List'[Id] ) }
VAR _FY = { MIN ( 'Project Progress List'[Financial Year] ) }
VAR _Qtr = { MIN ( 'Project Progress List'[Quarter] ) }
VAR _CPS = { MIN ( 'Project Progress List'[Corporate Plan Signa] ) }
-- hack to get Filters pane, Filters on this page/Filters on all pages specific filter value
VAR _FY_hack =
CALCULATE (
MIN ( 'Project Progress List'[Financial Year] ), // hack
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _FY_hack }
RETURN
_Return
EVALUATE
--Initiative Cost, filters, Qtr =
VAR _PMID = { MIN ( 'Project Progress List'[PjMaster IDId] ) }
VAR _PPLID = { MIN ( 'Project Progress List'[Id] ) }
VAR _FY = { MIN ( 'Project Progress List'[Financial Year] ) }
VAR _Qtr = { MIN ( 'Project Progress List'[Quarter] ) }
VAR _CPS = { MIN ( 'Project Progress List'[Corporate Plan Signa] ) }
-- hack to get Filters pane, Filters on this page/Filters on all pages specific filter value
VAR _Qtr_hack =
CALCULATE (
MIN ( 'Project Progress List'[Quarter] ), // hack
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _Qtr_hack }
RETURN
_Return
EVALUATE
--Initiative Cost, Current Score =
VAR _PMID = { MIN ( 'Project Progress List'[PjMaster IDId] ) }
VAR _PPLID = { MIN ( 'Project Progress List'[Id] ) }
VAR _FY = { MIN ( 'Project Progress List'[Financial Year] ) }
VAR _Qtr = { MIN ( 'Project Progress List'[Quarter] ) }
VAR _CPS = { MIN ( 'Project Progress List'[Corporate Plan Signa] ) }
VAR _CurrentScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
--'Project Progress List'[PjMaster IDId] = _PMID,
--'Project Progress List'[Id] = _PPLID,
ALLSELECTED (
'Project Progress List'[Corporate Plan Signa],
'Project Progress List'[Financial Year],
'Project Progress List'[Quarter]
)
)
VAR _Return = { _CurrentScore }
RETURN
_Return
EVALUATE
--Initiative Cost, Prevous Score =
/*
Summary boolean flag to denote whether cost status change from previous quarter
Details + comparisons only on adjoining quarters, we are only moving forwards in time sequence Q1 Q2 Q3 Q4
- but Q4 to Q1 will be a different FY ie yyyy-yy Q4 Vs yyyy+1-yy+1 Q1
Notes + 'Cost' now supercedes 'FTL' (Financial Traffic Light) terminology
History 202407 gt build
*/
VAR _PMID = { MIN ( 'Project Progress List'[PjMaster IDId] ) }
VAR _PPLID = { MIN ( 'Project Progress List'[Id] ) }
VAR _FY = { MIN ( 'Project Progress List'[Initiative Cost, filters, FY] ) } // hack
VAR _Qtr = { MIN ( 'Project Progress List'[Initiative Cost, filters, Qtr] ) } // hack
VAR _CPS = { MIN ( 'Project Progress List'[Initiative Cost, filters, CPS] ) } // hack
VAR _FYPrev = {
IF ( _Qtr <> "Q1",
_FY, -- no change
LEFT(_FY,4)-1 & "-" & RIGHT(_FY,2)-1 -- previous FY
) }
VAR _QtrPrev = {
SWITCH ( -- to previous quarter
_Qtr,
"Q1", "Q4",
"Q2", "Q1",
"Q3", "Q2",
"Q4", "Q3",
"Qe" -- error
) }
VAR _PreviousScore =
CALCULATE (
MIN ( 'Project Progress List'[Initiative FTL Status Scoring] ),
'Project Progress List'[PjMaster IDId] = _PMID,
'Project Progress List'[Corporate Plan Signa] = _CPS,
'Project Progress List'[Financial Year] = _FYPrev,
'Project Progress List'[Quarter] = _QtrPrev
)
--VAR _Return = { _FYPrev }
--VAR _Return = { _QtrPrev }
VAR _Return = { _PreviousScore }
RETURN
_Return
For the Initiative Cost, Prevous Score column we are hitting the record pair which should be qualified down to the previous quarter record via the filter hacks.
Lol will just go and add more bloat to the 'database'. Create a column for 'current score', 'previous score' and lastly a column for to flag if different.
Thanks kindly for your reply @Ritaf1983 have done as suggested and expanded my post for help with the problem
Short answer: Manipulating the specific filters in the filter pane with dax is not possible.
Long answer: It depends on what you're trying to achieve. Without more context, it's difficult to provide a specific solution.
Please share a pbix or some dummy data that keep the raw data structure with expected results? It should help us clarify your scenario and test to coding formula.
How to Get Your Question Answered Quickly
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly
User | Count |
---|---|
59 | |
58 | |
56 | |
38 | |
29 |
User | Count |
---|---|
82 | |
62 | |
45 | |
40 | |
39 |