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
dcheng029
Helper I
Helper I

How to create calculation from two data sources on Power BI?

Hi team,

 

I am working with two data sources simplified to the below example:

 

Data Source 1

NameTeamControl 1Control 2Control 3Control 4
John SmithACC C
Bob WillAC CC
Melissa TomBCCC 

 

Data Source 2

NameTeamControlsDate Conducted
John SmithAControl 105/2024
John SmithAControl 305/2024
John SmithAControl 306/2024
Bob WillAControl 105/2024
Bob WillAControl 206/2024
Melissa TomBControl 105/2024
Melissa TomBControl 105/2024
Melissa TomBControl 206/2024
Melissa TomBControl 406/2024

 

Data Source 1 shows a list of staff and which controls that are marked competent (C) in. Data Source 2 shows the list of staff and which controls they have conducted.

 

My goal here is to create a calculation that works out how many controls conducted by each staff (from Data Source 2) was those that were marked competent and incompetent (from Data Source 1).

 

Ultimately, I would like table visuals somewhat like the below:

NameNo. of Competent Controls ConductedNo. of Incompetent Controls ConductedAdherance Rate
John Smith1233%
Bob Will1150%
Melissa Tom3175%

 

TeamAdherance Rate (May 2024)Adherance Rate (June 2024)
A66%0%
B100%50%

 

Is this something that Power BI can support, and if so any guidance and instructions would be greatly appreciated!

1 ACCEPTED SOLUTION
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1720149365093.png

 


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

View solution in original post

9 REPLIES 9
Ashish_Mathur
Super User
Super User

Hi,

PBI file attached.

Hope this helps.

Ashish_Mathur_0-1720149365093.png

 


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

Hi Ashish,

Thank you so much for attaching your working file; definitely helpful seeing and replicating what you did!

 

You are welcome.


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

I was able to replicate your file and have everything working, but when I try to input some more data based off my actual dataset, along with a third data source I am running into some hurdles again.

 

I created a new forum if anyone has time to look through and advise?

https://community.fabric.microsoft.com/t5/Desktop/How-to-create-report-and-calculations-with-3-main-...

dulan_kavinda
Helper I
Helper I

Join Both Tablen on Name.

Add below column to Data Source 2 Table,

 

No. of Competent Controls Conducted =
IF (
    'Data Source 2'[Controls] = "Control 1" &&
    LOOKUPVALUE('Data Source 1'[Control 1], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 2" &&
    LOOKUPVALUE('Data Source 1'[Control 2], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 3" &&
    LOOKUPVALUE('Data Source 1'[Control 3], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 4" &&
    LOOKUPVALUE('Data Source 1'[Control 4], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C",
    1,
    0
)

 

----------------------------------------------------------

No. of Incompetent Controls Conducted =
IF (
    'Data Source 2'[Controls] = "Control 1" &&
    LOOKUPVALUE('Data Source 1'[Control 1], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 2" &&
    LOOKUPVALUE('Data Source 1'[Control 2], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 3" &&
    LOOKUPVALUE('Data Source 1'[Control 3], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C"
    ||
    'Data Source 2'[Controls] = "Control 4" &&
    LOOKUPVALUE('Data Source 1'[Control 4], 'Data Source 1'[Name], 'Data Source 2'[Name]) = "C",
    0,
    1
)
 
dulan_kavinda_0-1719901967618.png

 

Power BI File Attached - control.pbix

 

If I answer your question? Mark my post as a solution! Thank You!

fahadqadir3
Super User
Super User

@dcheng029First You need to Unpivot your Data Source 1.
In Power Query, Select the Control 1 to Control 4 columns.
Right-click and choose Unpivot Columns.
Rename the columns appropriately (Control and Competence)

Review the attached screenshot and pbix file. 

fahadqadir3_0-1719901498096.png

Controls.pbix

 

Hope it works.

Did I answer your question? Mark my post as a solution! This will help others on the forum!
Appreciate your Kudos!! 

 

Hey @fahadqadir3,

Thanks for the information and assistance!

I tried to follow the measures from @Shivu-2000's below comment as well as your tip to unpivot the controls columns, however when I create the table visual the numbers of Competent Controls Conducted and Incompetent Controls Conducted all seem incorrect (I am working with my true dataset which has a lot more entries within both data sources however the logic is still all the same).

 

Any ideas on where I have gone wrong?

Shivu-2000
Resolver IV
Resolver IV

Hi @dcheng029 
Follow these steps as:

1. Establish Relationship between both the data sources.

2. Create new Measures as:

  • Go to the "Modeling" tab and navigate to "New Measure."
  • Measure for Competent Controls Conducted:
Competent Controls Conducted = 
VAR _selectedName = SELECTEDVALUE('Data Source 2'[Name])
VAR _competentControls = 
    CALCULATE(
        COUNTROWS('Data Source 1'),
        FILTER(
            'Data Source 1',
            'Data Source 1'[Name] = _selectedName && 'Data Source 1'[Control 1] = "C"
                || 'Data Source 1'[Control 2] = "C"
                || 'Data Source 1'[Control 3] = "C"
                || 'Data Source 1'[Control 4] = "C"
        )
    )
RETURN
    IF(ISBLANK(_selectedName), BLANK(), _competentControls)
  •  Measure for Incompetent Controls Conducted:
Incompetent Controls Conducted = 
VAR _selectedName = SELECTEDVALUE('Data Source 2'[Name])
VAR _conductedControls = COUNTROWS('Data Source 2')
VAR _competentControls = CALCULATE([Competent Controls Conducted])
RETURN
    IF(ISBLANK(_selectedName), BLANK(), _conductedControls - _competentControls)
  • Measure for Adherence Rate:
Adherence Rate = 
VAR _competentControls = CALCULATE([Competent Controls Conducted])
VAR _conductedControls = CALCULATE([Incompetent Controls Conducted]) + _competentControls
RETURN
    IF(ISBLANK(_conductedControls), BLANK(), DIVIDE(_competentControls, _conductedControls, 0))

3. Building the Visuals:

  • Create a table with "Name" from Data Source 2.
  • Add the three measures you created ("Competent Controls Conducted," "Incompetent Controls Conducted," and "Adherence Rate") as separate columns.

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

Hi @Shivu-2000,

Thanks so much for the comprehensive info; much appreciated!

The names from Data Source 1 is actually more relevant than those from Data Source 2, how would i amend the measure to use the names from Data Source 1 instead? I've tried changing from:

VAR _selectedName = SELECTEDVALUE('Data Source 2'[Name])
to:
VAR _selectedName = SELECTEDVALUE('Data Source 1'[Name])
but it messes up the calculations.
 
Also, my actual dataset has hundreds of Controls, is there a more efficient way to include all controls on the "Competent Controls Conducted" measure of will I just have to type in a line for each control?
 
Thanks again for your assistance on this one!

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.