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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
Hadrey
Frequent Visitor

Calculating weights against the entire year with a multi-year table

Hello, i have a problem with claulating weight angist the entire year with multi-yert table
i have 2 tables one with

IDNAMEPRICEDATE

1

a2002023
2b3002023
1a1002024
1a5402023
1a3002023

and second with dictionary like

idnamebrandsubbrandfactorystatustype
1abr1subbr1fac1ncy
2bbr1subbr1fac1ncy
3cbr2subbr2fac1non


i have set relation between these 2 tables beacose i need to filter by name/brand etc.

I need something like this (sum of column weight needed to be 1):

 20232024weight 2023weight 2024
a10401000,77611
b300 0,2239 

 

i tired using

 

weight_2023 = DIVIDE(
 CALCULATE(
  SUM(TABLE1[PRICE]),
  TREATAS(VALUES(Years[YEAR]), TABLE1[DATE]),
  TREATAS(VALUES(DICTIONARY[ID]), TABLE1[ID])
 ),
 CALCULATE(
  SUM(TABLE1[PRICE]),
  TREATAS(VALUE(Years[YEAR]), Table1[DATE]
 )
)

 

 

but its only work when relationship is deactivated, but because of this other measures not work

2 REPLIES 2
Anonymous
Not applicable

Hi @Hadrey ,

Below is my table1:

vxiandatmsft_0-1717726855507.png

Below is my table2:

vxiandatmsft_1-1717726872034.png

You must create a column:

Column = CALCULATE(SUM('Table'[PRICE]),FILTER('Table','Table'[DATE] = "2023"))

and then you can create two measure:

Weight 2023 = 
  VAR _a = CALCULATE(SUM('Table'[PRICE]),FILTER('Table','Table'[DATE] = "2023"),ALLEXCEPT('Table','Table'[NAME]))
  VAR _b = SELECTEDVALUE('Table'[Column])
  RETURN
  DIVIDE(_a,_b)


Weight 2024 = 
  DIVIDE(CALCULATE(SUM('Table'[PRICE]),FILTER('Table','Table'[DATE] = "2024"),ALLEXCEPT('Table','Table'[NAME])),CALCULATE(SUM('Table'[PRICE]),FILTER('Table','Table'[DATE]="2024")))

The final output is shown in the following figure:

vxiandatmsft_2-1717726946520.png

Best Regards,

Xianda Tang

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

Hi, @Anonymous
First solution (with column) worked fine, but is not fit for my project, becouse I need to calculate weight but only for that what is after filter (setted by viewer by slicers) but in your solution is that when i applied slicer for name and select a then its show only 0,7761 but should show 1

and for second solution I have changed code to follow year 2023 and its showing only 1.0.

Hadrey_0-1717761119867.png

this is my `weight 2023`

Hadrey_1-1717761163689.png

`WEIGHT-2023`

Hadrey_2-1717761193205.png

and relationship on tables

Hadrey_3-1717761258846.png

 

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!

December 2024

A Year in Review - December 2024

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