Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Join 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.

Reply
marry
Helper I
Helper I

How to add a new column to transfer the new WW calucalation?

 

Hi everyone,

 

Would like to seek for the help.

How to add a new column and have transfer to the new WW caluculation? I have particular data would like to have the new WW display.

Logic: If Index=Qty, then new WW= WW+2; the rest keep the AS-IS WW vlaue

 

Expected Result:

marry_0-1700188152455.png

 

Best regards,

Marry

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @marry ,

Please try to create column with below dax formula:

 

RK = RANKX(FinanceCalendayDayExtView,[Fiscal Year Work Week],,DESC,Dense)
New Year =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _year =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[FiscalYear] ),
        FILTER ( ALL ( FinanceCalendayDayExtView ), [RK] = _a - 2 )
    )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", [Year ],
        _index = "Qty"
            && cur_ww = "WW99", [Year ],
        _index = "Qty", _year
    )
RETURN
    _result
New Month =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR cur_month = [Month]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _month =
    INT (
        RIGHT (
            CALCULATE (
                MAX ( FinanceCalendayDayExtView[YearMonth] ),
                FILTER ( FinanceCalendayDayExtView, [RK] = _a - 2 )
            ),
            2
        )
    )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", cur_month,
        _index = "Qty"
            && cur_ww = "WW99", cur_month,
        _index = "Qty", _month
    )
RETURN
    _result
New WW =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _ww =
    INT (
        CALCULATE (
            MAX ( FinanceCalendayDayExtView[WorkWeek] ),
            FILTER ( FinanceCalendayDayExtView, [RK] = _a - 2 )
        )
    )
VAR ww_1 =
    SWITCH ( TRUE (), LEN ( _ww ) = 1, "WW0" & _ww, LEN ( _ww ) = 2, "WW" & _ww )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", cur_ww,
        _index = "Qty"
            && cur_ww = "WW99", cur_ww,
        _index = "Qty", ww_1
    )
RETURN
    _result

 

vbinbinyumsft_0-1700461093157.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
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
Anonymous
Not applicable

Hi @marry ,

Please try to create column with below dax formula:

 

RK = RANKX(FinanceCalendayDayExtView,[Fiscal Year Work Week],,DESC,Dense)
New Year =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _year =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[FiscalYear] ),
        FILTER ( ALL ( FinanceCalendayDayExtView ), [RK] = _a - 2 )
    )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", [Year ],
        _index = "Qty"
            && cur_ww = "WW99", [Year ],
        _index = "Qty", _year
    )
RETURN
    _result
New Month =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR cur_month = [Month]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _month =
    INT (
        RIGHT (
            CALCULATE (
                MAX ( FinanceCalendayDayExtView[YearMonth] ),
                FILTER ( FinanceCalendayDayExtView, [RK] = _a - 2 )
            ),
            2
        )
    )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", cur_month,
        _index = "Qty"
            && cur_ww = "WW99", cur_month,
        _index = "Qty", _month
    )
RETURN
    _result
New WW =
VAR _index = [Index]
VAR cur_ww = [WW]
VAR cur_wwnum =
    INT ( RIGHT ( [WW], 2 ) )
VAR cur_year = [Year ]
VAR _a =
    CALCULATE (
        MAX ( FinanceCalendayDayExtView[RK] ),
        FILTER (
            ALL ( FinanceCalendayDayExtView ),
            [FiscalYear] = cur_year
                && [WorkWeek] = cur_wwnum
        )
    )
VAR _ww =
    INT (
        CALCULATE (
            MAX ( FinanceCalendayDayExtView[WorkWeek] ),
            FILTER ( FinanceCalendayDayExtView, [RK] = _a - 2 )
        )
    )
VAR ww_1 =
    SWITCH ( TRUE (), LEN ( _ww ) = 1, "WW0" & _ww, LEN ( _ww ) = 2, "WW" & _ww )
VAR _result =
    SWITCH (
        TRUE (),
        _index = "BOH", cur_ww,
        _index = "Qty"
            && cur_ww = "WW99", cur_ww,
        _index = "Qty", ww_1
    )
RETURN
    _result

 

vbinbinyumsft_0-1700461093157.png

Please refer the attached .pbix file.

 

Best regards,
Community Support Team_Binbin Yu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hello @Anonymous ,

 

Appreciated your help!!!!:)

Many thanks for the detailed DAX and attached file.

Bmejia
Super User
Super User

Here are two possible methods.

Assuming your data does not change, your text value start with 2 characters and the number is aways the third character in this column you can use something like this.
NE_WW2 =
Var WW_Value= left(YOURTABLE[WW],2)
Var WW_Num = MID(YOURTABLE[WW],3,5)+2
return
IF(
(CONTAINSSTRING(YOURTABLE[WW],"WW")=TRUE())
&& YOURTABLE[Index]="QTY"
,WW_Value & WW_Num
,YOURTABLE[WW])

 

2nd Method prefer to use as it will adjust more easily to the data

Transform the data

1st Duplicate the WW column

2nd Split the column By Non-Digit to Digit will split text and numbers

Bmejia_2-1700252036560.png

 

Change the number from text to numeric if text format (In my example is WW2.2)

Add a custom column called “New WW”

=If Text.Contains([WW], "WW") and [Index]="Qty" then [WW2.1]&Number.ToText([WW2.2]+2)

  else [WW]

You can keep the two new columns that were split or just do not choose the column during transformation.

Bmejia_3-1700252036562.png

 

 



Hello @Bmejia ,

 

Thanks for the professional and deatiled solution explanation.

I just found out I missed to consider the cross year situation.

 

The requirment is more like I would like to move back 2 weeks( add 2 weeks) for the pariticular data (Index=Qty), and add some new columns to reflect the new WW, Month and Year.

I have another table in my Power BI is the calender raw data. Would like to refer to this calender table and reflect the result in the new added WW, Month, Year columns. 

 

Expected Result:

marry_0-1700280825217.png

(Some Index= Qty data, the WW= WW99, for those data would also keep the AS-IS value for the New Year, Month & WW columns)

 

Calender Table in my Power BI: (Please check my PBI file)

marry_1-1700281472019.png

 

It seems I cannot insert the PBI file here directly, I put it in google drive, please let me know whether you can see it.) Thanks for the help!!!!

 https://drive.google.com/file/d/1SslxfMwmjQ_Yl8np31CFKoQ8-pL-QIQy/view?usp=sharing 

 

Best regards,

Marry

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.