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

Sum Product row based on lookup value

Hi,

 

I have 12 columns one next to the other representing salaries per month. I also have another different table with pay periods (26 of them), and a multiplier for each month.

 

What I want is to add a column in the Salary table that computes the year to date salary, based on the number of payrolls lapsed (1 to 26). Say I'm at payroll 13, for each row, the function would lookup 13 in the Multiplier Table, and multiply that row with the all of my Salary Table months, so that some months are multiplied by 1, some by a fraction, and the rest by 0.

 

Here is the Salary Table:

 

PersonJanuaryFebruaryMarchAprilMayJuneJulyAugustSeptemberOctoberNovemberDecember
Mary100100100100100100100100100100100100
David909090909090909090909090
Joseph808080808080808080 808080

 

Here is the Multiplier table:

# Payrolls2021-01-012021-02-012021-03-012021-04-012021-05-012021-06-012021-07-012021-08-012021-09-012021-10-012021-11-012021-12-01
10,451612900000000000
20,903225800000000000
310,39285710000000000
410,89285710000000000
5110,3548387000000000
6110,8064516000000000
71110,266666700000000
81110,733333300000000
911110,19354840000000
1011110,64516130000000
11111110,1000000
12111110,5666667000000
131111110,032258100000
141111110,48387100000
151111110,935483900000
1611111110,38709680000
1711111110,83870970000
18111111110,3000
19111111110,7666667000
201111111110,225806500
211111111110,677419400
2211111111110,13333330
2311111111110,60
24111111111110,0645161
25111111111110,516129
26111111111110,9677419

 

Thanks!

1 REPLY 1
Anonymous
Not applicable

This can be done in DAX, but we will have to write a little bit of unnecessary DAX code to achieve this. But from the "best practices" point of view, in any data model or table, ideally you should have only one column/field for one particular type of data. For example, your salary table should look like this...

 

PersonMonthSalary
MaryJanuary100
MaryFebruary100
MaryMarch100
JosephOctober80
JosephNovember80
JosephDecember80

 

Similarly, your Payroll table should have the following structure...

# PayrollsMonthMultiplier
11-Jan-210.4516129
21-Jan-210.9032258
31-Jan-211
41-Jan-211
51-Jan-211
241-Dec-210.0645161
251-Dec-210.516129
261-Dec-210.9677419

 

Month, Date, etc... should have only one field instead of having a column for each month or each date.

 

Before, giving you the solution, I would like to know the following...

 

1) What is your data source? Is it an excel file? Because it unlikely that any database will store the information in this fashion.

2) Is it possible for you to convert the data into the form I suggested at the source itself?

3) If that is not possible, are you okay to pivot them in PowerQuery while importing the data into Power BI Desktop?

4) Is there any specific reason for you to have the data in the way you have kept it other than the reason that you want to see or present it in that form in visuals? If visualization is the reason, it can be handled in visuals itself. 

5) You said that if you are in Payroll 13, the calculation should happen accordingly? But how does the system know that you are in Payroll 13? Is it based on the current date? or is it based on a slicer or filter where the user will choose the current payroll number? While writing the DAX code, we need this information also to calculate the result.

 

I would like to tell you that, writing DAX code is one skill, but having the data model in the best possible way following the best practices is another important thing. Because the way data is stored will make your DAX codes easier to write. Although with DAX skills, you can do nearly all kinds of things you can imagine, you should try to model your data correctly, and then the results can be achieved with simpler DAX codes.

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.