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
janzitniak
Frequent Visitor

How to calculate ratio between totals by months in different tables without relationship

Hello,

I have a 2 tables without relationship with following data:

Table name 2020 (download)

Date

Type

Amount

2020/01/15

DF

100

2020/01/19

VDD

200

2020/01/20

IUD

300

2020/02/20

IUD

150

2020/02/23

IUD

250

2020/02/27

VDD

350

2020/03/10

DF

200

2020/03/17

DF

300

2020/03/18

VDD

400

 

Table name 2021 (download)

Date

Type

Amount

2021/01/31

VDD

110

2021/01/31

IUD

220

2021/01/31

VDD

330

2021/02/28

VDD

180

2021/02/28

DF

300

2021/02/28

DF

420

2021/03/31

DF

260

2021/03/31

VDD

390

2021/03/31

IUD

520

 

I would like to calculate total of amount by every month (january, february, march) for each year (2020 and 2021) and to calculate ratio between years for every month as follow:

(Total amount of 2020 by month / Total amount of 2021 by month) * 100

and to visualise them (table, crosstab or chart).

Regards

Jan

1 ACCEPTED SOLUTION
zzcc
Frequent Visitor

Hi,   @janzitniak 

To get the month number in each table:

month20 = MONTH('2020'[Date])
Month21 = MONTH('2021'[Date])
 
To create a month table contains each month(1~12), then build 1to many relationship with 20/21 table.
And then to create 3 measures:
mTotal2020 = CALCULATE(SUM('2020'[Amount]),FILTER(ALL('2020'),EOMONTH('2020'[Date],0)=EOMONTH(MAX('2020'[Date]),0)))
 
mTotal2021 = CALCULATE(SUM('2021'[Total]),FILTER(ALL('2021'),EOMONTH('2021'[Date],0)=EOMONTH(MAX('2021'[Date]),0)))
 
radio = DIVIDE([mTotal2020],[mTotal2021])
 

result:

zzcc_0-1627824560099.png

PBIX:

https://drive.google.com/file/d/15_8-X-ZzxEbu-eIeEamcohl43ykZs8Qo/view?usp=sharing

 

 

Best Regards

Zerrick

Did I answer your question? Mark my post as a solution!

 

View solution in original post

4 REPLIES 4
mahoneypat
Microsoft Employee
Microsoft Employee

You definitely should append those two tables in the query editor (and this disable load on the two source tables), to simplify your analysis and visualization.

 

Pat

 





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

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


Thank you Pat for your approach and idea.

Jan

zzcc
Frequent Visitor

Hi,   @janzitniak 

To get the month number in each table:

month20 = MONTH('2020'[Date])
Month21 = MONTH('2021'[Date])
 
To create a month table contains each month(1~12), then build 1to many relationship with 20/21 table.
And then to create 3 measures:
mTotal2020 = CALCULATE(SUM('2020'[Amount]),FILTER(ALL('2020'),EOMONTH('2020'[Date],0)=EOMONTH(MAX('2020'[Date]),0)))
 
mTotal2021 = CALCULATE(SUM('2021'[Total]),FILTER(ALL('2021'),EOMONTH('2021'[Date],0)=EOMONTH(MAX('2021'[Date]),0)))
 
radio = DIVIDE([mTotal2020],[mTotal2021])
 

result:

zzcc_0-1627824560099.png

PBIX:

https://drive.google.com/file/d/15_8-X-ZzxEbu-eIeEamcohl43ykZs8Qo/view?usp=sharing

 

 

Best Regards

Zerrick

Did I answer your question? Mark my post as a solution!

 

Thank you Zerrick for your useful answer, it works as I expected. 

P.S.: Is it correct If I create in MONTH table a following measure for calculating ratio (it works in same way as yours):

Ratio = SUM('2020'[Amount])/SUM('2021'[Total])

and then is not neccessary to create measures mTotal2020  and mTotal2021 as in your case.

Jan

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!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

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.