cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sentsara
Helper II
Helper II

Calculated column [CY_LY_Flag ] -Help needed

Existing Dataset

DimTable

sentsara_1-1620330659271.png

 

FactSales 

sentsara_0-1620330642231.png

 

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

 

 

 

1 ACCEPTED SOLUTION
yingyinr
Community Support
Community Support

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"
    )

yingyinr_1-1620715617353.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
daxer-almighty
Solution Sage
Solution Sage

@sentsara 

 

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.

sayaliredij
Solution Supplier
Solution Supplier

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

Thanks for your quick reply on this.
we need to consider based on the LatestMonth value 'Y' or 'N' as well.

yingyinr
Community Support
Community Support

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"
    )

yingyinr_1-1620715617353.png

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
PBI User Groups

Welcome to the User Group Public Preview

Check out new user group experience and if you are a leader please create your group!

MBAS on Demand

Microsoft Business Applications Summit sessions

On-demand access to all the great content presented by the product teams and community members! #MSBizAppsSummit #CommunityRocks

Get Ready for Power BI Dev Camp

Power BI Dev Camp - June 24th

Mark your calendars and join us for our next Power BI Dev Camp!

Top Solution Authors
Top Kudoed Authors