I'm used to Powerquery's sequential command structure where each new step references the output of the previous one, like...
I'm having trouble figuring out how to structure a series of transformations like the one above.
I'd appreciate any advice, or links to references or helpful hints out there for someone going from PowerBI to SQL.
There are multiple ways to achieve this. One simple way is
Combining steps 1 and 2. Selecting a,b, and c columns, and then calculating a new column iseven .
select a,b,c, case when b%2 = 0 then 'even' else 'odd' end iseven, from t1
Left join with t2.
select a,b,c, case when b%2 = 0 then 'even' else 'odd' end iseven, [t2.y] y from t1 left join t2 on t1.a = t2.y
Using groupby on iseven column and aggregating columns a,b and c. Here we use will wrap the above query in a subquery.
select sum(a) sumofA, sum(b) sumofB, sum(c) sumofC, Sum(y) sumOfY from ( select a,b,c, case when b%2 = 0 then 'even' else 'odd' end iseven, t2.zy from t1 left join t2 on t1.a = t2.y ) master group by iseven
For the final left join with t3.
select sumofA,sumofB,sumofC, t3.Z from ( select sum(a) sumofA, sum(b) sumofB, sum(c) sumofC, Sum(y) sumOfY from ( select a,b,c, case when b%2 = 0 then 'even' else 'odd' end iseven, t2.zy from t1 left join t2 on t1.a = t2.y ) master group by iseven ) resultTillstep4 left join t4 on resultTillstep4.sumofA = t3.Z
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.