I am using SSAS Tabluar models and I am trying to create a calculated table based on the count of each subcategory.
ColumnA ColumnB
SPN100 new
SPN100 old
SPN100 new
SPN200 new
SPN200 old
and I am trying to create a new table based on counts of ColumnB
Column A Counts
SPN100 3
SPN200 2
You can use SUMMARIZE or SUMMARIZECOLUMNS.
Summary = SUMMARIZE(Table, Table1[ColumnA], "Counts", COUNT(Table1[ColumnB]))
Summary = SUMMARIZECOLUMNS(Table1[ColumnA], "Counts", COUNT(Table1[ColumnB]))
Related
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) )
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
I have the following view set up in SQL Server:
VIEW
(left table: population data per year; middle table: municipalities; right table: municipality areas in km²)
Query
SELECT
dbo.T_GEMEINDE.GKZ, dbo.T_GEMEINDE.NAME,
dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE.FLAECHE_KM2 / dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE.DAUERSIEDLUNGSRAUM_KM2 AS [ges. Fläche / Dauersiedlungsr.],
dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN.J2017 / dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE.FLAECHE_KM2 AS [ges. Bevölkerungsdichte],
dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN.J2017 / dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE.DAUERSIEDLUNGSRAUM_KM2 AS [Bevölkerungsdichte Dauersiedlungsraum]
FROM
dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE
INNER JOIN
dbo.T_GEMEINDE ON dbo.T_BASE_DAUERSIEDLUNGSRAUM_GEMEINDE.GKZ = dbo.T_GEMEINDE.GKZ
INNER JOIN
dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN ON dbo.T_GEMEINDE.GKZ = dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN.GKZ
The last column in the view contains a calculation (population density for 132 municipalities for a certain year) for the year 2017 and uses the column J2017 from the table seen on the left. This is the output (Bevölkerungsdichte Dauersiedlungsraum):
Current output:
OUTPUT
Desired output:
The rightmost column (Bevölkerungsdichte Dauersiedlungsraum) seen in the provided output screenshot has the output data of the calculation for the year 2017. The same output has to be generated for all the other years, but each as a separate column.
Question: how do I perform the calculation which you can see in the last column in the view for all years (J2017-J2050) without having to do it manually for each year column?
Thanks in advance.
if you want someone to provide you with a complete solution then you will need to supply:
CREATE TABLE statements for the 3 tables
INSERT INTO... statements to provide sample data for all 3 tables
However, if you just want a suggestion about how to approach this problem then I would use an UNPIVOT statement to create a view/table that
holds all the columns in dbo.T_BASE_GEMEINDE_BEVOELKERUNG_JAHR_BEGINN
apart from the "year" columns (J2017, J2018, j2019, ...)
adds a single "year" column with values from 2017 to 2050
adds a single value column to hold the population for each year
By joining your existing tables to this new table/view and grouping by your new "year" column you should achieve what you want
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
I have a table as shown in the image. I need to create two filters in PowerPivot:
Group1Member_On_Any_Day: Set to 1 if any record in Group1MemberFlag is set to 1
Group1Member_On_All_Days: Set to 1 if all records in Group1MemberFlag is set to 1
The problems that I am running into are:
How do I filter on an aggregate
How do I ensure the aggregate filters are applied as I slice my
table by date or CustomerId
CustomerMembershipTable
I had a Eureka moment and realized that the filtering has to be done in the measure and that measure should be used to view the aggregations. For example, if I wanted to count customers who are a member of Group1, I would create a measure as follows:
Cnt_Customer_In_Group1:=Calculate(DISTINCTCOUNT([CustomerId]),FILTER('CustomerTable',[Group1MemberFlag]=1))
If you also have a measure that counts distinct CustomerIds, you can a filter on Group1MemberFlag to see which customerIds are in Group1 and which are not in Group1.