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
Dhruvin
Helper III
Helper III

What is the best way to apply Nested Relationship same as SQL Statements?

Hello,

 

I'm trying to achieve the following SQL Statement's result into Power BI.

SELECT Coalesce(c.name, 'Andre Transportører') AS name, 
       Count(*)                                 Bookings, 
       Coalesce(t2.totinv, 0)                   AS Invoiced, 
       Coalesce(t2.freightcost, 0)              AS InvFreight, 
       Count(*) - Coalesce(t2.totinv, 0)        AS NotInvoiced, 
       Coalesce(t2.freightcost, 0) / Coalesce(t2.totinv, 1) * ( Count(*) - 
       Coalesce(t2.totinv, 0) )                 AS Avsetning 
FROM   carriers c 
       right join tplbookings t 
               ON c.id = t.carrierid 
       left join (SELECT i.carrierid, 
                         Coalesce(Count(*), 0)                        AS TotInv, 
                         SUM(Coalesce(w.netamount, 0) 
                             + Coalesce(w.totalamountfromcharges, 0)) AS 
                         FreightCost 
                  FROM   waybills w 
                         inner join invoices i 
                                 ON w.invoiceid = i.id 
                  WHERE  i.invoicestatus <> 'Draft' 
                         AND i.customerid = 1067 
                         AND w.departuredate BETWEEN 
                             '2019-06-01' AND '2019-06-30' 
                  GROUP  BY i.carrierid) t2 
              ON t.carrierid = t2.carrierid 
WHERE  t.customerid = 1067 
       AND departuredate BETWEEN '2019-06-01' AND '2019-06-30' 
GROUP  BY c.name, 
          t2.totinv, 
          t2.freightcost 
ORDER  BY Count(*) DESC

I 'm getting the following end result with above SQL Statement.

Screenshot_3.png

Now, I have tried to apply the same relationship within my Power BI tables and and take all the parameters from the where conditions as a slicer in Power BI and Select statement as a column from table. Still I'm not getting the correct result.

 

What I'm missing here in relationship? Or what is the best way to achieve this type of result in Power BI?

Screenshot_4.png

 

Any help really appriciated !


Thanks

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi @Dhruvin ,

 

SUMMARIZECOLUMNS should work.

https://docs.microsoft.com/en-us/dax/summarizecolumns-function-dax

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

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.

Top Solution Authors