Sum and relates tables DAX - dax

I do have a table(1) containing the cost and the Project number, line number and item number and would like to get the cost summarized in another table(2) in a new column where im having the project number and project line also. The second table does not have the item number and does also contain budget figures on the more aggregate level. The two tables are linked on Keyz.
Table1
Item Cost PjNumb PjLine Keyz
------------------------------------------------------------
Q000001403 24,35 QP00032 11300102 QP0003211300102
Q000001405 24,35 QP00002 11100102 QP0000211100102
Q000001404 24,35 QP00003 11200202 QP0000311200202
Table2
PjNumb PjLine Budget keyz
------------------------------------------
HG00057 1910 190000 HG000571910
HG00057 111001 190000 HG00057111001
HG00057 111002 0 HG00057111002
Ive done the following formula in table2
=CALCULATE(SUM(Table1[Cost]);ALL(Table1[keyz]))
I'm not getting any value out in the new column in table2.
Hope some one are able to help me. The Pjnumb and PjLine in table1 is retreived from a third table, not shown here.
Kr
Jan

Related

Power Bi count rows for all tables in one measure

In my power Bi I would like to count rows for all my tables and having this output:
Table Name
Row count
Table1
126
Table2
985
Table3
998
...
...
As long as I have few tables I can do
NEWTABLE = UNION(
ROW("TableName","Table1", "Rowcount",ROWSCOUNT(Table1)),
ROW("TableName","Table2", "Rowcount",ROWSCOUNT(Table2)),
...
)
But this starts to be complicated when I have many tables.
Is there a way I can do it? Like a loop or something?
Thank you
If you only need a metrics then you can use DaxStudio -> ViewMetrics
where cardinality is your "rowCounts"
If you need something more, then you can get all table name from DMV
select * from $SYSTEM.TMSCHEMA_TABLES
populate this as another table in your model, and use M language to loop through.
here useful example:
https://community.powerbi.com/t5/Power-Query/Power-query-Counting-rows-from-all-table-in-query-editor-but-not/td-p/1198489

update table from chilled table with group by in oracle

i have two tables master and other is child. suddenly i have lost voucher_date in master table. now how can i update it from child table where many record inserted against one voucher_number.
i have tried the query
update salem set (vch_date,vch_temp)=(
SELECT
vch_date,
vch_no
FROM sale where salem.vch_no=sale.vch_no GROUP BY vch_no,vch_date);
but i got message
SQL Error: ORA-01427: single-row subquery returns more than one row
01427. 00000 - "single-row subquery returns more than one row"
Regard.
GROUP BY you used is, actually, DISTINCT applied to selected column list. It appears that - for a certain vch_no which establishes relation between those two tables - you don't have a distinct vch_date + vch_no combination, which also means that there are several vch_date values for each vch_no. What to do? Pick one, for example maximum.
Also, you're setting salem.vch_temp to sale.vch_no which is pointless as vch_no from sale is equal to vch_no from salem so you can set salem.vch_temp to salem.vch_no.
UPDATE salem m SET
m.vch_date = (SELECT MAX(s.vch_date)
FROM sale s
WHERE m.vch_no = s.vch_no
),
m.vch_temp = m.vch_no;

Complex count row etl requirement

I have a requirement related as below
1-If there is employee record then count the number of rows
a-if there are four rows then follow the layout 1,
and populate the column1 and column 2 with values in report and ltrimrtrim
b- if there are three rows, then follow the layout 2,
and hardcode the column 1 and column 2 with NULL
Otherwise, look for the employee record.
Couldn't get the logic, I used the router with as if column 1 and two null the send to layout two else 1. But the requirement is different.
router transformation, if null, layout one else 2
Step 1 - Use SRT>AGG>JNR to calculate count. create new column as count_all and set to COUNT(*). Please group by proper key columns.
Step 2 - Use RTR next to split data based on your condition.
group 1- count_all =4 then follow the layout 1 and...
group 2- count_all =3 then follow the layout 2 and...
group 3 - if count <3 then do employee record.

Type wise summation and subtracting in oracle

I have two table of my store and working on Oracle. Image First table describe about my transaction in store, there are two types of transaction (MR & SR), MR means adding products in Store and SR means removing products from my storage. What I wanted to do get the final closing of my storage. After transaction final Quantity every products as shown in Image. I have tried many solution but can't finish it. so I could not show now. Please help me to sort this problem. Thanks
You can use case as below to decrease and increase the quantity based on type and then group by Name and find the sum of quantity derived from the case statement to get your desired result.
select row_number() over (order by a.Name) as Sl,a.Name, sum(a.qntity) as qntity
from
(select t2.Name,case when t1.type='MR' then t2.qntity else -(t2.qntity) end as qntity
from table1 t1,table2 t2 where t1.oid=t2.table01_oid) a
group by a.Name;
This query will provide result as below:
SL NAME QNTITY
1 Balls 0
2 Books 6
3 Pencil 13

Count Length and then Count those records.

I am trying to create a view that displays size (char) of LastName and the total number of records whose last name has that size. So far I have:
SELECT LENGTH(LastName) AS Name_Size
FROM Table
ORDER BY Name_Size;
I need to add something like
COUNT(LENGTH(LastName)) AS Students
This is giving me an error. Do I need to add a GROUP BY command? I need the view:
Name_Size Students
3 11
4 24
5 42
SELECT LENGTH(LastName) as Name_Size, COUNT(*) as Students
FROM Table
GROUP BY Name_Size
ORDER BY Name_Size;
You may have to change the group by and order by to LENGTH(LastName) as not all SQL engines let you reference an alias from the select statement in a clause on that same statement.
HTH,
Eric

Resources