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
Existing Dataset
DimTable
FactSales
Based on FactSales.LatestMonth='Y', we need to Flag the calculated column CY_LY_Flag ="Yes" or "No" for the below two condition.
Get the LatestMonth='Y' and mark that as "Yes"
same time Last year also needs to be flagged as "Yes"
remaining records should be "No"
Expected output: for CY_LY_Flag through Calculated Column
FactSales
BatchDate CY_LY_Flag
03/01/2021 Yes
02/01/2021 No
02/01/2021 No
02/01/2019 No
12/01/2019 No
11/01/2019 No
03/01/2020 Yes
Solved! Go to Solution.
Hi @sentsara ,
You can create a calculated column as below:
CY_LY_Flag =
VAR _maxdate =
CALCULATE ( MAX ( 'FactSales'[BatchDate] ), ALLSELECTED ( 'FactSales' ) )
RETURN
IF (
YEAR ( 'FactSales'[BatchDate] )
IN { YEAR ( _maxdate ), YEAR ( _maxdate ) - 1 }
&& MONTH ( 'FactSales'[BatchDate] ) = MONTH ( _maxdate ),
"Yes",
"No"
)
Best Regards
Please do yourself a favour and do not create unnecessary columns in fact tables. The column you're after should belong to DimTable, not your to fact table. Also, latestmonth should be moved to DimTable.
Hi @sentsara
You can try following DAX for a calculated column
CY_LY_Flag =
var years = {YEAR(TODAY()), YEAR(TODAY())-1 }
RETURN
IF(MONTH(FactSales[BathDate]) = MONTH(TODAY()) && YEAR(FactSales[BatchDate]) IN years,"Yes","No")
Regards,
Sayali
If this post helps, then please consider Accept it as the solution to help others find it more quickly
Proud to be a Super User!
Thanks for your quick reply on this.
we need to consider based on the LatestMonth value 'Y' or 'N' as well.
Hi @sentsara ,
You can create a calculated column as below:
CY_LY_Flag =
VAR _maxdate =
CALCULATE ( MAX ( 'FactSales'[BatchDate] ), ALLSELECTED ( 'FactSales' ) )
RETURN
IF (
YEAR ( 'FactSales'[BatchDate] )
IN { YEAR ( _maxdate ), YEAR ( _maxdate ) - 1 }
&& MONTH ( 'FactSales'[BatchDate] ) = MONTH ( _maxdate ),
"Yes",
"No"
)
Best Regards
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 |
---|---|
133 | |
90 | |
88 | |
64 | |
58 |
User | Count |
---|---|
202 | |
137 | |
106 | |
70 | |
68 |