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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
PowerBI_User16
New Member

Calculating accros multiple columns and visualizing with a timeline

Hi,
I have created a table with example data for YEAR (2022 - 2025), 10 different account numbers per year, company code, attributes (opening balance, january - december), value, debit (debit: positive), credit (credit: negative) The opening balance is the value from the previous year in december. The other values are the change in the month. I would like to calculate the following values in a new column. For example: January = 10500 February = 10300 March = 10600 April = 10500 May = 10350 etc.'
I have another column for Day_Month_Year, which has a relationship to a Mapping_date table. 

How can I calculate the correct value for each month and year and use a timeline to visualize the result?

 

YEAR ACCOUNT COMNPANY CODE ATTRIBUTE VALUE DEBIT/CREDIT
2022100001000Opening balance10000.0010000.00
2022100001000January500.00500.00
2022100001000February-200.00-200.00
2022100001000March300.00300.00
2022100001000April100.00100.00
2022100001000May-150.00-150.00
2022100001000June200.00200.00
2022100001000July250.00250.00
2022100001000August-100.00-100.00
2022100001000September350.00350.00
2022100001000October-50.00-50.00
2022100001000November150.00150.00
2022100001000December400.00400.00
2022200001000Opening balance5000.005000.00
2022200001000Januar-300.00-300.00
..................
2023100001000Opening balance11750.0011750.00
2023100001000January600.00600.00
..................
2024300001000Anfangsbestand8000.008000.00
2024300001000Januay-200.00-200.00
..................
2025400001000Anfangsbestand15000.0015000.00
2025400001000January800.00800.00
..................
 

I have introduced two calculated columns subcategories to categorize the data:

Subcategory =

SWITCH(

    TRUE,

    CALCULATE(COUNTROWS(FILTER('GLFUNCT', 'TABLE'[COMPANY CODE] IN {"1000"}))) > 0, "1. Productionmaterial",

    CALCULATE(COUNTROWS(FILTER('GLFUNCT', 'TABLE'[COMPANY CODE] IN {"2000", "3000"}))) > 0, "3. Consumables, supplies and goods",

     "2. UE_FE_Total"

)

 

Subcategory 1 =

SWITCH(

    TRUE,

    'TABLE'[COMPANY CODE] IN {"1000"}, "2.1 TEST",

    'TABLE'[COMPANY CODEr] IN {"2000"}, "2.2 TEST",

    'TABLE'[COMPANY CODE] IN {"3000", "4000"}, "2.3 TEST",

    BLANK()

)

 

 



5 REPLIES 5
V-yubandi-msft
Community Support
Community Support

Hi @PowerBI_User16 ,

We haven’t received a response yet and want to ensure the solution met your needs. If you need any further assistance, feel free to reach out we’d be happy to help. If everything is working as expected, kindly mark it as Accepted as solution.

 

Thank You.

V-yubandi-msft
Community Support
Community Support

Hi @PowerBI_User16 ,

May I ask if you have resolved this issue? If so, please mark the helpful reply and accept it as the solution. This will be helpful for other community members who have similar problems to solve it faster.

 

Thank you.

V-yubandi-msft
Community Support
Community Support

Hi @PowerBI_User16 ,

I wanted to check if you had the opportunity to review the information provided. Please feel free to contact us if you have any further questions. If my response has addressed your query, please accept it as a solution and give a 'Kudos' so other members can easily find it.

Thank you.

V-yubandi-msft
Community Support
Community Support

Hi @PowerBI_User16 ,

@bhanu_gautam logic is sound and provides a strong foundation. I have a couple of suggestions in line with Power BI best practices.

  1. Instead of comparing month names (e.g., January <= February), it's more effective to create a separate Month Number column (with values 1 to 12). This approach ensures your calculations are accurate and your visuals are sorted correctly.
  2. For improved performance and flexibility, consider using a DAX measure rather than a calculated column, especially when your calculation must adjust based on context (for instance, filtering by year, account, etc.). Measures are evaluated at query time, offering more dynamic behaviour for your visuals.

Vyubandimsft_0-1745485640659.png

Helpful Reference: Learn DAX basics in Power BI Desktop - Power BI | Microsoft Learn

 

Thnaky you for your inputs @bhanu_gautam .

 

If my response resolved your query, kindly mark it as the Accepted Solution to assist others. Additionally, I would be grateful for a 'Kudos' if you found my response helpful.

 

 

bhanu_gautam
Super User
Super User

@PowerBI_User16 First, create a calculated column to compute the running total for each month. This column will add the monthly changes to the opening balance.

 

RunningTotal =
VAR CurrentYear = 'TABLE'[YEAR]
VAR CurrentAccount = 'TABLE'[ACCOUNT]
VAR CurrentMonth = 'TABLE'[ATTRIBUTE]
VAR OpeningBalance = CALCULATE(
MAX('TABLE'[VALUE]),
'TABLE'[ATTRIBUTE] = "Opening balance",
'TABLE'[YEAR] = CurrentYear,
'TABLE'[ACCOUNT] = CurrentAccount
)
VAR MonthlyChanges =
CALCULATE(
SUM('TABLE'[VALUE]),
'TABLE'[YEAR] = CurrentYear,
'TABLE'[ACCOUNT] = CurrentAccount,
'TABLE'[ATTRIBUTE] <= CurrentMonth,
'TABLE'[ATTRIBUTE] <> "Opening balance"
)
RETURN
OpeningBalance + MonthlyChanges

 

Ensure you have a date table to map the Day_Month_Year column. This table should include all dates within the range of your data.

DAX
DateTable =
CALENDAR(
MIN('TABLE'[Day_Month_Year]),
MAX('TABLE'[Day_Month_Year])
)

 

Create a relationship between the Day_Month_Year column in your main table and the date column in the DateTable.

 

Use a line chart to visualize the running total over time. Set the Day_Month_Year from the DateTable as the axis and the RunningTotal as the values.

You already have the subcategories calculated. Ensure these are used as needed in your visualizations to filter or categorize the data.

 

 




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

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

August 2025 community update carousel

Fabric Community Update - August 2025

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