cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper I
Helper I

Creating a Measure

Hi,

 

I made a calculationg in SQL.. and i need to convert it to a measure in Power BI.

In my SQL i have 3 tables (FactParkingViolation,DimIssuer,DimIssuingAgency), when i added the the tables to Power BI i made a megre between the two tables - DimIssuer & DimIssuingAgency. so now I have two tables in Power BI -FactParkingViolation and DimIssuer. 

I'm not so familiar with Dax that's way i don't know how to create this measure.

Help will be much appriciated!

 

This is the SQL Query:

 

 SELECT SUM(IssuingAgencyAverageYearlySalary)*0.03

 FROM(

 SELECT DISTINCT(DI.IssuerID) ,IssuingAgencyAverageYearlySalary

  FROM FactParkingViolation FPV LEFT JOIN

 DimIssuer DI ON FPV.IssuerKey = DI.IssuerKey

 LEFT JOIN DimIssuingAgency DIA

 ON DI.IssuingAgencyCode = DIA.IssuingAgencyCode

 WHERE YEAR(IssueDate) = 2016 ) R

8 REPLIES 8
Microsoft
Microsoft

Hi @SHAKEDALROY ,

Could you tell me if your problem has been solved?
If it is, kindly Accept it as the solution. More people will benefit from it.
Or you are still confused about it, please provide me with more details about your table and your problem or share me with your pbix file from your Onedrive for Business.


Best Regards,
Stephen Tao

Microsoft
Microsoft

Hi @SHAKEDALROY ,

 

You could leran the merge from this link.

 

After you merged, try this measure.

 

CALCULATE(SUM('Table'[IssuingAgencyAverageYearlySalary]),FILTER('TABLE',YEAR([IssueDate]) = 2016))*0.03

 

Best Regards,

Stephen Tao

 

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

Super User III
Super User III

@SHAKEDALROY  the DAX For this is simple: 

 

Salary Measure = SUM(FactParkingViolation[IssuingAgencyAverageYearlySalary])*0.03

 

Or if you want it always for the year 2016:

UPDATED SYNTAX: 

Salary 2016 = SUMX(FILTER(FactParkingViolation, RELATED(Table[IssueDate]) = 2016), [IssuingAgencyAverageYearlySalary])*0.03)

 

The trick is creating the relationships. You don't need to do the Merge if you don't want to, but you do need to create relationships on FPV.IssuerKey = DI.IssuerKey and  DI.IssuingAgencyCode = DIA.IssuingAgencyCode

 

https://excelwithallison.blogspot.com/search?q=relationships

 

 


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

Hi @AllisonKennedy  thank you for your reponse,

 

i needed to make that merge for different calculations.. i tried to add 'related' to the DAX formula you wrote to me but it still doesn't work, do you know way?

thank you.

image.png

@SHAKEDALROY  It looks like you have an extra ) before the comma. Sorry, that was my fault as it was in my formula too. That's what I get for writing DAX blindly!


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

i think something is still missing @AllisonKennedy /:

The result in SQL is 18,639,996

and when i tried your formula in Power BI the result is 451,796,281

How have you done the merge? Did you remove duplicates, your SQL code uses DISTINCT, which we haven't accounted for in the DAX. Also, it's possible to increase rows in merge if you're not careful. https://excelwithallison.blogspot.com/2020/10/merge-ahead-one-for-one.html 

 


Has this post solved your problem? Please mark it as a solution so that others can find it quickly and to let the community know your problem has been solved. 


If you found this post helpful, please give Kudos.


I work as a trainer and consultant for Microsoft 365, specialising in Power BI and Power Query. 


www.excelwithallison.com

Super User IV
Super User IV

@SHAKEDALROY , You have create 1 - Many retion between dimesions and fact

DimIssuingAgency - FactParkingViolation, DimIssuer -FactParkingViolation , Also join FactParkingViolation with date table having year on IssueDate (Date[Date])

 

Then You can add +0 in the measure you are creating to have left join

 

To get the best of the time intelligence function. Make sure you have a date calendar and it has been marked as the date in model view. Also, join it with the date column of your fact/s. Refer :radacad sqlbi My Video Series Appreciate your Kudos.



Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!
Dashboard of My Blogs !! YouTube Channel !! Connect on Linkedin

Proud to be a Super User!

Helpful resources

Announcements
secondImage

Congratulations!

We are excited to announce the Power BI Super Users!

Microsoft Ignite

Microsoft Ignite

Join digitally, March 2–4, 2021 to explore new tech that's ready to implement. Experience the keynote in mixed reality through AltspaceVR!

secondImage

The largest Power BI virtual conference

100+ sessions, 100+ speakers, Product managers, MVPs, and experts. All about Power BI. Attend online or watch the recordings.

Top Solution Authors
Top Kudoed Authors