Sum based on different column from model in Power BI - sum

I have data from two tables modelled as follows:
my desired result is:
I've tried SUM(table1[balance],ALLEXCEPT(table1,table1[account])) - doesn't work
this may be simple, but PowerBi is evading me at this point...

Pretty simple to solve it by with extra steps to complete it:
First, on your second table (I named it "cust"), add a new column with the balance from your first table (I named it "acc"):
Balance = LOOKUPVALUE(acc[balance],acc[account ],cust[account])
Cust
Next, I will add a new column to lookupvalue on my "acc" table, follow by adding new column to return the sum value from my "cust" table:
sum = CALCULATE(SUM(cust[Balance]),FILTER(cust,cust[customer ]=EARLIER(acc[customer])))
Acc

Related

Qlik - Building a dynamic view

I have a SQL query that creates a table, and every month 2 new columns will be added for that table related to the current month.
I have tried without success to set up a flat table (visual) in Qlik that will automatically expand every month to include these table. Is there a way to do this, and i so please point me in the right direction.
You can have a look at CrossTable prefix.
This prefix allows a wide table to be converted to a long table.
So if we have data like this:
After running the following script:
CrossTable:
CrossTable(Month, Sales)
LOAD Item,
[2022-10],
[2022-11],
[2022-12],
[2023-01],
[2023-02],
[2023-03],
[2023-04]
FROM
[C:\Users\User1\Documents\SO_75447715.xlsx]
(ooxml, embedded labels, table is Sheet1);
The final data will looks like below. As you can see there are only 3 columns. All xls month columns (after Item) are now collapsed under one field - Month and all the values are collapsed under Sales column.
Having the data in this format then allows creating "normal" charts with adding Month column as dimension and use sum(Sales) as an expression.
P.S. If you dont want to manage the new columns being added then the script can be:
CrossTable(Month, Sales)
LOAD
Item,
*
FROM
...

Need a dynamic range/bucket in SSAS and would like to use it as a column in the power bi matrix

In a SSAS cube, I have a table called Workload with ID and CATG as columns.
and another table Hierarchy with ID and Name
I need output in the following way
*Range = number of DISTINCT CATG from Workload table.
I need the count of IDs from Workload based on the Range.
Can you please help me with this?
I tried to create Range as a column in the Workload table. But as it is a column and not a metric, we cant apply any other filters from other tables. If I create it as a metric, I cant use it as a column in pbi matrix.
You can do this with an additional unconnected SupportTable, where you need to store range Label, Min and Max value per range:
CountOfIDs = var _rangeMin = SELECTEDVALUE(SupportLabel[MinVal]) var
_rangeMax = SELECTEDVALUE(SupportLabel[MaxVal]) return COUNTROWS( FILTER( SUMMARIZE('Workload','Workload'[ID],"distvalperid", calculate(DISTINCTCOUNT(Workload[CTRG]) )), [distvalperid] <=
_rangeMax && [distvalperid] >= _rangeMin) )

SSRS Query result in one cell based on other cells in the same row

Have not yet had to do this in SSRS and I'm scratching my head.
Basically, I have a tablix based on DataSet 1. The tablix is sorted and grouped on a field called AssemblyName and it is also the first column value. The second column value is based on the sum of a field called Quantity. (in the database table, each row has an AssemblyName value and a Quantity value)
The tricky part is this: There is another table in the database that contains a 'snapshot' of the AssemblyName and Quantity based on older (original) data.
And in my Tablix I want to show a cell in the same row that Sums the old Quantities for the AssemblyName in the first cell of the row. The old Quantities would be pulled from the database table with the old data.
Basically, the goal is the show a Tablix grouped and sorted by AssemblyName, and have the following columns in the tablix: Assembly Name (from current DB table), the current Quantity sum (from current DB table), and the old Quantity sum (from another DB table with the old data).
I have everything working except for the cell that contains the old Quantity sum from the old DB table.
The old DB table is in the same database, so that is not an issue, what my problem is, creating a query that sums the Quantities in the old table based on the value of the AssemblyName in the same Tablix row.
I've tried creating Dataset 2 with a query based on parameters pulled from Dataset 1, and then writing this expression in the old quantity cell:
=Sum(Fields!Quantity.Value, "Dataset 2")
I'm getting blank values in every cell in the third column, which contains the expression above. I'm assuming it because the Dataset 2 is not actually reading the values of AssemblyName in the same tablix row. The essence of what I want to do, however, is pass the value from the first column in the tablix, which contains AssemblyName, to the WHERE clause in the query for Dataset 2 whose parameter is in turn shown in the third column's cell in the same tablix row.
In case it helps, the query from DataSet 2 is as follows:
SELECT AssemblyName
, Quantity
FROM OldData
WHERE AssemblyName = #compare_AssemblyName
I hope this makes sense, but please ask questions as needed so that I can clarify.
Regards.
You should be able to pull the old data in along with your new data in the same query, then just sum the respective fields:
SELECT AssemblyName
, NewQuantity = n.Quantity
, OldQuantity = COALESCE(o.Quantity, 0)
FROM NewData n
LEFT JOIN OldData o
ON n.AssemblyName = o.AssemblyName
WHERE n.AssemblyName = #compare_AssemblyName

Power query - dynamic parameters

I have created 4 separate tables via sql code on sqlserver and I want to create one filter for all 4 using a common column i.e. month on power query. Usually, I would create 4 pivot tables and create 4 slicers for say, month. Can I dynamically create just one filter for the 4 pivots on PQ? I have seen examples of anti-joins but I don't see this working in my example. If any questions like this already exist, links to them will be much appreciated.
Cheers,
Mo
Table.SelectRows can takes a function as its second parameter, so you can create your filter function in one query and reference that query in the parameter.
For example, if I wanted to filter a column Value to only have numbers greater than 30, you would create a query with the following formula:
= (row) => row[Value] > 30
Let's call that query FilterValue. Then, if you wanted to use this filter on a table in step Step, you would add the following step (with the fx button next to the formula bar):
= Table.SelectRows(Step, FilterValue)
If you need to use the filter again in another query with the step OtherStep, add the following step:
= Table.SelectRows(OtherStep, FilterValue)

How can I create filter based on two different fields with OR operator between them in Power View?

For example I want to filter my data based on next filter expression:
lead_veh_of_interest starts with 'BMW 1'
OR
sale_model starts with 'BMW 1'
how can I achieve this?
Are these fields both in the same table? If so you could create a calculated column that performs that conditional. Then filter the view on the resulting calculated column.
For example you could create the following calculated column.
Calculated Column: "Starts With BMW 1"
Equation:
=IF(OR(Left([lead_veh_of_interest starts], 5) = "BMW 1", Left([sale_Model], 5) = "BMW 1"), 1, 0)
Then in the view set the filter so that [Starts With BMW 1] = 1
I found acceptable solution (thanks for all suggestions - it was very helpful).
First of all I redesigned my model and (how #Mike_Honey suggsts me) created dedicated table with consolidated information I want to filter. Next I connected this new table with existing tables and created hierarchy from fields I want to give to the end users for step-wise filtering (previously I split down old fields contained information I want to filter into more granular level). Now it is possible to filter data by any combination of models in any combination of request types (sale, lead, competitor, etc) using hierarchy.