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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
adavid999
Helper V
Helper V

simple calculated column and rearrange data

Hi, I am (still!) just getting started w Power BI and have a question re calculated columns. I have table data like this:

YearQuestionScore
2019I agree50
2019I do not agree60

2019

I don't care40
2018I agree40
2018I do not agree20
2018I don't care20

 

What is the best, most efficient way to get data to this (for a visual):

Question20192018Difference
I agree504010
I do not agree602040
I don't care402020

 Would appreciate any help, many thanks.

A

1 ACCEPTED SOLUTION

Sorry my mistake

this year = calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])))
Last year = calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])-1))

 

divide( calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])))
, calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])-1)))-1
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

View solution in original post

6 REPLIES 6
amitchandak
Super User
Super User

Create a year calendar and join with this table.
Use Year from year table in visual

this year = calculate(sum(Table[Score]), Year[Year]= max(Year[Year]))
Last year = calculate(sum(Table[Score]), Year[Year]= max(Year[Year])-1)
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

Thanks @amitchandak . I have a couple of questions, I hope you don't mind - I am really new to this.

 

Is a 'year calendar' table like this?

Year
2017
2018
2019

And if so, is this then joined to my main table on 'Year'?

 

And then when i write your measures, do I write them exactly as you have indicated, or do I insert values(e.g. 2017, 2018 etc) for years?

 

Will these measures automatically subtract per the questions I included in my original post? ('I agree with this', 'I do not agree with this', etc)

Best,

Adam

 

Yes, the Table will be like that.

When you plot this year vs last year with the view/group by year from year table, you will able to see the switch, the name can be anything but it will not show year name unless you use the year as group by

 

YOY or change % = [This year]/[last year] -1

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

Thanks @amitchandak 

I get this error when writing your measure - can you see what I am doing incorrectly?

Capture1.PNG

And I don't need % year difference - just a straightforward YOY subtraction.

Best,

A

Sorry my mistake

this year = calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])))
Last year = calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])-1))

 

divide( calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])))
, calculate(sum(Table[Score]), filter(Year,Year[Year]= max(Year[Year])-1)))-1
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

Thanks @amitchandak , I appreciate your help.

A

Helpful resources

Announcements
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!

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.