简体   繁体   中英

SQL Query to DAX (in Power BI) with multiple joins, count, group by

I am new to Power BI and am trying to learn DAX after having been exposed to SQL. I have messed around in Power BI with the Group by function, but am not sure how that works when you have a count in the select statement and multiple joins. I have also tried the option where you import data from SQL Server and paste this query and that works, but it makes it independent of other data visualizations in Power BI when I add a date slicer from another table.

My goal is to make this query into a pie chart. Then I would like to have a date slicer for date/PTO date so that you can designate a time frame and the pie chart will update with the correct count by state.

SQL Query:

SELECT
    state,
    Count(ptodate) AS TotalPTO 
FROM
    solar.solar.accounts AS sa 
    JOIN
        solar.solar.systems AS ss 
        ON sa.systemid = ss.systemid 
    JOIN
        solar.solar.addresses AS sad 
        ON sa.addressid = sad.addressid 
    JOIN
        solar.solar.customerassociatedepccalculations AS sepc 
        ON sa.customerid = sepc.customerid 
    JOIN
        solar.reference.merchants AS rm 
        ON sa.merchantid = rm.merchantid 
WHERE
    sepc.active = 1 
    AND rm.merchantid = 4 
GROUP BY
    state;

So DAX is for calculations to the data after you already have it imported; It's not for querying.

For querying you'd do one of 3 things:

Use the GUI of PowerQuery (ie go to 'Get Data' & click through)

Write the M Code yourself (this is a different language than DAX - and honestly not really worth doing usualy)

Or just use SQL like you currently are Get Data > SQL Server > Advanced Options, and just paste in your query

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM