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
Anonymous
Not applicable

Yearly sum takes values of other years

Hello,

 

I need help to build a measure used in a difference from a data set. I have the following data:

 

OWNERMONTHYEARPRODUCTNUMBER
PETEROct2021FRUIT5
PETEROct2021HERBS6
PETEROct2021CARROT3
PETEROct2021TOMATO4
PETEROct2021PEACH8
PETEROct2021APPLE9

 

OWNERMONTHYEARPRODUCTNUMBERSUM 2019
PETEROct2019BERRY10110
PETEROct2019PINEAPPLE6110
PETEROct2019WATERMELON2110
PETEROct2019CORN3110
PETEROct2019LETTUCE9110
PETEROct2019PEAS80110

 

The problem I'm having is that I need to build a measure which only calculates the difference between any 2021 value (or any year fot hat matter), vs 2019 total sum ONLY.

 

When I build the metric I obtain the following:

OWNERMONTHYEARPRODUCTNUMBERSUM 2019DIFFERENCE
PETEROct2021BERRY 110-110
PETEROct2021PINEAPPLE 110-110
PETEROct2021WATERMELON 110-110
PETEROct2021CORN 110-110
PETEROct2021LETTUCE 110-110
PETEROct2021PEAS 110-110
PETEROct2021FRUIT5110-105
PETEROct2021HERBS6110-104
PETEROct2021CARROT3110-107
PETEROct2021TOMATO4110-106
PETEROct2021PEACH8110-102
PETEROct2021APPLE9110-101

 

As you can see, the new table is considering all rows products from 2019 when I only need 2021 (or any other year that I choose) exclusively since I will chart the difference between fixed 2019 sum and the number from 2021.

 

Couple of things to consider:

- Data is under Live Connection so I can't modify or add any data/tables/etc.

- All the metrics (OWNER, PRODUCT, YEAR, MONTH, ETC) come from different tables in the original data set (except YEAR and MONTH that come from "Calendar" table)

- I can't just "Filter" the table to "not show blank values" under "NUMBER" column.

 

Please let me know any options I could use to calculate the difference and just report it for 2021 (or any other year), the idea is that SUM 2019 is a fixed value (constant) not affected by any slicers or filter, while the other data is, and can be substracted to any metric I choose (NUMBER in this case).

 

Thank you for your support.

5 REPLIES 5
Ashish_Mathur
Super User
Super User

Hi,

Try this approach.  Remove the last column from the second table.  Using the Query Editor, append both tables.  In the appended table, create another column of proper date entries (from the Year and Month column - assume the date to be 1).  Create a Calendar Table and build a relationship from the Date column of the appended table to the Date column of the Calendar Table.  In the Calendar Table, write calculated column formulas to build a Year column.  To your visual, drag Year and Month from the Calendar Table & drag Product and Owner from the appended dataset.  Write these measures

Total = sum(Data[Number])

Total in 2019 = calculate([Total],calendar[year]=2019)

DIfference = [total]-[Total in 2019]

Hope this helps.


Regards,
Ashish Mathur
http://www.ashishmathur.com
https://www.linkedin.com/in/excelenthusiasts/
Anonymous
Not applicable

Hello, 

 

I am not able to manipulate the tables or even the Query Editor on Power BI since they are all grayed out and its a live connection file, so I can't do the first steps of what you mentioned.

 

The tables I made to ask the questions are results in a visual I created in the worksheet dragging the different metrics to it (from different tables).

 

Any sugestions? Thank you.

Hi @Anonymous 

Due to you use live connection mode, you may create measures to achieve your goal.

Could you show me more details about your tables? A screenshot or sample data may be better.

You can provide me with a sample data by your onedrive for business.

This may make it easier for me to understand your data model and your requirement.

 

Best Regards,

Rico Zhou

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly. 

 

amitchandak
Super User
Super User

@Anonymous , In that case choose 2021 in year slicer. Better to year in a separate Table ot date table

 

Try a meausre like

 

measure =
var _year = 2019
return
sum(Table[NUMBER]) - calculate(sum(Table[NUMBER]), filter(all(Table[Year]), Table[Year] =2019))

or


measure =
var _year = 2019
return
sum(Table[NUMBER]) - calculate(sum(Table[NUMBER]), filter(all(Table), Table[Year] =2019))

Anonymous
Not applicable

Hello,

 

The metrics shown in the example are from different tables, not from the same, "Table", also, this formula is only showing the values for 2020, not the actual difference, is it possible that there could be a mistake?

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.