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

Power Bi Dax create table from other tables and measure

Hi I'm pretty new to Power Bi, and am wondering if anyone can help on the issue below? I'm struggled for more than 2 weeks and still couldn't figure out how to do it.  Thanks

 Table "Adviser"

Adviser KeyAuthority
1A
2B
3C
4B
5A

 

Table "Practice"

Adviser keyPractice keyPractice group keyPractice group name

 

How can I use Dax to create a table like below

Practice group nameNo. of advisers with Authority "A"No. of advisers with Authority "B"

 

The relationship between table "practice" and table "adviser" is Many to One, linked by adviser key

1 ACCEPTED SOLUTION

@Karen1025 

you can create two measures.

No.ofA = CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="A"))

No.ofB = CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="B"))

1.PNG

if you want to create a table, you can try this

 

Table = SUMMARIZE('Practice',Practice[Practice group key],"NO. of A",CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="A")),"NO.of B",CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="B")))

pls see the attachment below.





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

Proud to be a Super User!




View solution in original post

9 REPLIES 9
TomMartens
Super User
Super User

Hey @Karen1025

 

I'm not recommending to create a 3rd table, from my understanding of your requirement it will be sufficient to create two measures.

Assuming the relationships between your two tables looks like this:

image.png

Then you can create two measures like so:

Advisors with A = 
COUNTROWS(
    FILTER(
        CALCULATETABLE(
            'Advisor'
            , CROSSFILTER( 'Advisor'[Adviser Key] ,Practice[Adviser key] , Both )
        )
        , 'Advisor'[Authority] = "A"
    )
)

and so

Advisors with B = 
COUNTROWS(
    FILTER(
        CALCULATETABLE(
            'Advisor'
            , CROSSFILTER( 'Advisor'[Adviser Key] ,Practice[Adviser key] , Both )
        )
        , 'Advisor'[Authority] = "B"
    )
)

This lets you create a visual using the Table visual like so

TomMartens_0-1648102334818.png

I highly recommend reading through this tutorial about data modeling in Power BI: https://docs.microsoft.com/en-us/learn/paths/model-power-bi/?WT.mc_id=DP-MVP-5003068

This article explains how you can create a measure: https://docs.microsoft.com/en-us/power-bi/transform-model/desktop-measures?WT.mc_id=DP-MVP-5003068

 

Hopefully, this helps to tackle your challenge.

Regards,
Tom

P.S.: Enjoy your Power BI journey, from my personal experience i can tell that there is more joy than tears 🙂

 



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Hi Tom, I have to create a table for the further calculation, but your measures worked on my report. Thanks anyway. 

ryan_mayu
Super User
Super User

@Karen1025 

could you pls provide the sample data of table practice and the expected output?





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

Proud to be a Super User!




Hi Ryan,

Please find my tables below

 

Table"Adviser"

Adviser KeyAuthority
A01A
A02B
A03A
A04B
A05A
A06B
A07A
A08A


Table "Practice"

Adviser keyPractice keyPractice group key
A01P001G1
A02P002G1
A03P003G2
A04P004G2
A05P001G1
A06P002G1
A07P003G2
A08P004G2

 

Expected Output

Practice group nameNo. of advisers with Authority "A"No. of advisers with Authority "B
G122
G231

@Karen1025 

you can create two measures.

No.ofA = CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="A"))

No.ofB = CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="B"))

1.PNG

if you want to create a table, you can try this

 

Table = SUMMARIZE('Practice',Practice[Practice group key],"NO. of A",CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="A")),"NO.of B",CALCULATE(DISTINCTCOUNT(Adviser[Adviser Key]),FILTER(Adviser,Adviser[Authority]="B")))

pls see the attachment below.





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

Proud to be a Super User!




Thanks so much Ryan, this is exactly what I want. You solved my 2 weeks nightmare. 

you are welcome





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

Proud to be a Super User!




Karen1025
Frequent Visitor

@amitchandak Thanks for your advise. I'm pretty new to PowerBI, could you please give me an example about how to write the Dax?

amitchandak
Super User
Super User

@Karen1025 , Merge in power query.

 

Summarize in DAX can work as these are joined tables you can select many table in table and then can use another table.

 

Or you can also check Natural joins

https://www.sqlbi.com/articles/from-sql-to-dax-joining-tables/

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.