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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Upali63
Helper II
Helper II

Create New Column with Data from Same table

Hi Friends

 

I have a data table as per sample below where the values in Amount Column alwayas show on accumulated basis as at end of each month. Now I want to create a new coloum subtracting current month value against the same item from the Amount  in the next month. Therefore please help me to achieve this since I am new to power bi

 

Upali63_0-1695809091051.png

 

19 REPLIES 19
v-binbinyu-msft
Community Support
Community Support

Hi @Upali63 ,

I'm a little confused about your needs, Could you please explain them further? 

What is the logic for calculating your desired result, please explain it.

vbinbinyumsft_0-1695957434651.png

Thanks for your efforts & time in advance.

 

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.

Hi CST

In my data table Values are recorded in a such a way that as at end of each month end Cumulative values are shown in the Amount Column. Eg as at 31-01-22 Value for Petrol 92 (121,257,402.15) is for the month of Jan-22 whereas as at 28-02-22 the value for Petrol-92 (133,449,144)is is Jan and Feb Total Value. Now I want to subtract Jan 22 figure from Feb figure (133,449,144-121,257,402.15=12,242,741.85) and record the same in Expected New Column. The needs to be done based on month end date as well as Item shown (eg Petrol 92) Ac_Description Column pls. I hope I have clarified the issue and look forward to your help please.

 

Hi @Upali63 ,

Please try below steps:

1. below is my test tabel

vbinbinyumsft_0-1695977468823.png

2. create a new column with below dax formula

Column =
VAR cur_date = [Date]
VAR next_date =
    EDATE ( cur_date, 1 )
VAR cur_acc = [Acc_description]
VAR cur_amt = [Amount]
VAR next_val =
    CALCULATE (
        MAX ( [Amount] ),
        FILTER ( ALL ( 'Table' ), [Date] = next_date && [Acc_description] = cur_acc )
    )
RETURN
    IF ( ISBLANK ( next_val ), cur_amt, next_val - cur_amt )

vbinbinyumsft_1-1695977533544.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.

Thanks for you reply. Here I too have made a mistake

My desired result should be like below pls

 

Upali63_0-1695979458370.png

Kindly help me

 

Hi CST,

Data in my table are recorded in such a way that at the end of each month Amount shown is the cumulative value as at end of month. Eg as 31-Jan-22 the Values for that particular month "Petrol 92  121,257,402.15 " is for the month Jan 22. However when It comes as at 28-Feb-2022 Amount shown is 133,499,144 (Jan+Feb) . So I want to subtract from Feb figure (133,499,144) the value for Jan (121,257,402.15) and need to get the result 12,241,741.85 . That is the amount I need to be shown in Expected New Column. Here I need this subtraction to be done against each Item in Acc_Description column Please. Hope I have clarified it and look forward to your help please.

pradeep_kare12
Resolver I
Resolver I


Open your Power BI Desktop file.In the Fields pane on the right-hand side, select your data table.In the Modeling tab, click on "New Column."In the formula bar that appears at the top, you can use the DAX formula to create the new column. You can use the LAG function to retrieve the value from the next month and subtract it from the current month's value. Here's an example formula :


NewColumn = YourTable[Amount] -
CALCULATE(SUM(YourTable[Amount]),
FILTER(YourTable, YourTable[Month] = EARLIER(YourTable[Month]) + 1)
)

Thanks for Your help

I did as you said and below is the result pls. Kindly look into that help me

 

Upali63_3-1695872536102.png

 

 

Hi pradeep,

Could you have a look at my issue and help me please.

 

CoreyP
Solution Sage
Solution Sage

Try something like:
SUM( Value ) - CALCULATE( SUM( Value ) , PARALLELPERIOD( 'Dates'[Date] , 1 , MONTH ) )

Thanks for your help

But I get the below result when I added a column as you said

Upali63_4-1695872833177.png

Pls correct me

Oh, you created that as a calculated column. It needs to be a measure. Additionally, you need to set up a date dimension table in your model. The 'Dates'[Date] segment of my DAX function references the date table you need to set up. 

Thanks

Did As you advised and below is the result

Upali63_0-1695875213858.png

 

Can you share a screenshot of the relationships in your model view? 

Upali63_0-1695876234485.png

 

For some reason this seems to work:

CoreyP_0-1695878071555.png

 

It is working Thanks lot

It works only if I repalce Calender[Date] with Table (TB) [date]

If you dont mind can you help me to achieve same thing with a calculated column please

 

Upali63_0-1695880153179.png

 

Ohhh, I see what I did wrong. It's aggregating only for the date granularity, and not taking into account the account type. 

Could you then share the correct measure that I should write  please. Thanks a lot

Upali63
Helper II
Helper II

Appreciate if you help me please

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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