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

Get certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now

Reply
Sashwato
Helper II
Helper II

Need help with YTD Calculated Column per record field

Hello Team,

 

I am trying to create a Calculated column that calculates the YTD values per cora_acc_code-accountnumber basis. There are 165 distinct accountnumber records for which I am calculating YTD based on Period date column given in the snapshot below. The period date has values for end of the month and YTD end date is 12/31 in our dataset.

Can anyone help me out with the Calculated column formula per accountnumber record here?

 

cora_acc_id records.PNG

 

The following are my entries in period date:

 

period date.PNG

1 ACCEPTED SOLUTION
selimovd
Super User
Super User

Hey @Sashwato ,

 

the following measure should do it. I added some explanations what the mesaure is doing:

YTD Measure = 
-- save account and date of current row in a variable
VAR vAccountRow = myTable[cora_acc_code-accountnumber]
VAR vDate = myTable[Period Date]

-- calculate the sum and filter table to off rows of
-- the current year that are smaller or equal to the row date
VAR vResult =
    CALCULATE (
        SUM ( myTable[Sum of Value] ),
        ALL ( myTable ),
        myTable[cora_acc_code-accountnumber] = vAccountRow
        && YEAR ( myTable[Period Date] ) = YEAR ( vDate )
        && myTable[Period Date] <= vDate
    )
RETURN
    vResult

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

View solution in original post

4 REPLIES 4
TheoC
Super User
Super User

Hi @Sashwato 

 

You should be able to use the below and just use a Matrix visual with your Code Column in the rows and the Date as Column headers:

 

Calculated Column = TOTALYTD ( SUM ( Table[ColumnName] ) , Table[DateColumn] ) 

 

Hope this helps 🙂

 

Theo

 

If I have posted a response that resolves your question, please accept it as a solution to formally close the post.

Also, if you are as passionate about Power BI, DAX and data as I am, please feel free to reach out if you have any questions, queries, or if you simply want to connect and talk to another data geek!

Want to connect?www.linkedin.com/in/theoconias

selimovd
Super User
Super User

Hey @Sashwato ,

 

the following measure should do it. I added some explanations what the mesaure is doing:

YTD Measure = 
-- save account and date of current row in a variable
VAR vAccountRow = myTable[cora_acc_code-accountnumber]
VAR vDate = myTable[Period Date]

-- calculate the sum and filter table to off rows of
-- the current year that are smaller or equal to the row date
VAR vResult =
    CALCULATE (
        SUM ( myTable[Sum of Value] ),
        ALL ( myTable ),
        myTable[cora_acc_code-accountnumber] = vAccountRow
        && YEAR ( myTable[Period Date] ) = YEAR ( vDate )
        && myTable[Period Date] <= vDate
    )
RETURN
    vResult

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 

Hey Denis,

 

This is perfect! I got it to work finally. Thank you so much.

 

Regards!

amitchandak
Super User
Super User

@Sashwato , if you need a new column

new column =
var _year = year([Period date])
var _date =[period date]
return
sumx(filter(Table,[cora_acc_code-accountnumber] =earlier([cora_acc_code-accountnumber]) && year([Period date]) =_year && [period date] =_date),[Sum of Value])

 

 

If you need a measure use time intelligence

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

Join us as experts from around the world come together to shape the future of data and AI!
At the Microsoft Analytics Community Conference, global leaders and influential voices are stepping up to share their knowledge and help you master the latest in Microsoft Fabric, Copilot, and Purview.
️ November 12th-14th, 2024
 Online Event
Register Here

Helpful resources

Announcements
November Carousel

Fabric Community Update - November 2024

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

Live Sessions with Fabric DB

Be one of the first to start using Fabric Databases

Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.

Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.

Nov PBI Update Carousel

Power BI Monthly Update - November 2024

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