Forum Discussion

SHAKEDALROY's avatar
SHAKEDALROY
Icon for Helper I rankHelper I
5 years ago

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

  • 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.

  • AllisonKennedy's avatar
    AllisonKennedy
    Icon for Community Champion rankCommunity Champion

    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

     

     

    • SHAKEDALROY's avatar
      SHAKEDALROY
      Icon for Helper I rankHelper I

      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.

      • AllisonKennedy's avatar
        AllisonKennedy
        Icon for Community Champion rankCommunity Champion

        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!

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.

  • Anonymous's avatar
    Anonymous
    Not applicable

    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