Consolidating multiple rows to a single row - reportingservices-2005

Is it possible to join multiple row values to a single row? The stored procedure from where I acquire the data that I use return multiple, almost identical rows except that the category-column dfferentiates for products that have been assigned multiple categories. I would like to consolidate these categories to one column, separated by new lines. Example data:
Name Article number Sales Sales Category
------------------------------------------------
Product 1 2059102-1 20520 Retailer 1
------------------------------------------------
Product 1 2059102-1 20520 Retailer 2
------------------------------------------------
Product 1 2059102-1 20520 Retailer 3
------------------------------------------------
Product 2 2059102-2 2050 Retailer 1
------------------------------------------------
Product 2 2059102-2 5302 Retailer 3
Desired result:
Name Article number Sales Sales Category
------------------------------------------------
Product 1 2059102-1 20520 Retailer 1
Retailer 2
Retailer 3
------------------------------------------------
Product 2 2059102-2 2050 Retailer 1
Retailer 3
Thank you!

Create an RDL table and setup a Grouping on the Detail section of the table with two grouping expressions (so you have a single Grouping in the Table Details, but with multiple grouping expressions). The grouping expressions should be one for each of the fields: Name, Article number.
Then put a column in the RDL table for each field (Name, Article number, Sales, Sales Category). The trick is putting a List control in the Sales Category cell. In the list add a textbox for the "Sales Category" field and I think you'll get the result you want.
There is also some nasty SQL tricks for "row concatenation", but that is not very maintainable IMHO.

Related

How to correct the error, A table of multiple values was supplied where a single value was expected, when used with SELECTCOLUMNS in DAX

I have a table 1- Invoices report that looks like this:
Invoice Number
Customer Number
1
cus1
2
cus2
3
cus3
4
cus4
...
...
I want to make a column that has only the Customer Number.
I have used the following Expression:
Invoice Customers Number =
SELECTCOLUMNS(
'1- Invoices report',
"Customer Number",
'1- Invoices report'[Customer Number]
)
With this I am getting the error A table of multiple values was supplied where a single value was expected.
Any solution for this?
The result of SELECTCOLUMNS() is a table, not a column.
Make sure to use it as a calculated table, not a calculated column or measure:

How to put measures from multiple tables into one matrix in Power BI?

I have 8 tables with data of sold products. Each table is about a unique product. In Power BI, I want to create a matrix, containing the sold quantities (values) per product (rows), per month (columns), and the number of unique customers who bought the products.
Each of the 8 tables with the sales data has the following structure. So the App ID is different for each table, but is constantly the same within a table. Example for a Cars table:
Customer ID Month App ID
29273 2020-3 1
90283 2018-5 1
55824 2016-12 1
55824 2018-10 1
55824 2021-1 1
So, a bicycle table would have the same structure, but then the App ID's would be, for example 2, in the entire table.
I have two tables that are connected with the 8 product tables in a one-to-many relationship. The Calendar table based on the Month column, and the App table based on the App ID column.
The table Calendar:
Month
2015-1
2015-2
2015-3
2015-4
2015-5
...
...
The table Apps:
ID Name
1 Cars
2 Bicycle
3 Scooter
4 ...
So, the structure is:
I created the Calendar en Apps tables so that I could use them for the matrix, but it doesn't work like I want so far. At the end, I want to create a matrix like this (where P = the number of products sold, and C = the number of customers in that month for that product):
Product 2015-1 2015-2 2015-3 2015-4 2015-5 ...
P C P C P C P C P C
Cars 3 2 5 5 7 6 2 1 4 2
Bicycle 11 9 17 14 5 5 4 4 8 6
Scooter ...
Skateboard ...
As mentioned, I made that Calendar and App table so that I can use the columns from it to fill the labels in the rows and columns. What I am unable to do is create such a 'general variable' of the number of products sold per product, and the number of customers associated with it.
Can someone explain to me how I can fill the matrix with the numbers of products (and customers) sold, so that the matrix looks like the one described above?
I think this is pretty straight forward. You actually don't need the 'Calendar' table as it only contains the same info as is already in the 'Sales' table.
You should configure the matrix like this:
Rows: 'Name' (from the 'Apps' table)
Columns: 'Month' (from the
'Sales' table)
Values:
C = Count distinct of CustomerId (from 'Sales' table) [this counts the unique customers per month and app)
P = Count of CustomerId (from 'Sales' table) [this counts the rows of the 'Sales' table which is your number of products if every row represents 1 sale)
The different aggregations (count distinct, count) can be found under the Values' options:

How do I handle complex relations with Laravel?

Although code-based answers are much appreciated, but I'm interested in knowing the logic behind handling this, as it might happen again later.
I'm working on an eCommerce project. Most products are variables. Imagine a shirt for example.
A shirt can have 5 different sizes ( XS, S, M, ML, L ) and 3 colors ( Red, Green, Blue ). These are examples, these attributes are dynamic and can be edited any time. My approach was to create 3 different tables for the product itself:
- main_product_table
- id
- product_variant_table
- id
- main_product_id
- product_variant_combination_table
- id
- variant_id
- attribute_name_id
- attribute_value_id
And 2 more tables for the attributes:
- attribute_name_table
- id
- attribute_name
- attribute_value_table
- id
- attribute_value
So, for example the said shirt will now creates the following records:
2 records in attribute_name_table
3 records in attribute_value_table
1 record in main_product_table
3x5 records in the product_variant_table
2x3x5 records in the product_variant_combination_table ( 2 rows each holding the value of 1 attribute )
Now consider querying all products that include a XS size, or query the product with all of its variation data.
My questions are:
Can eloquent models handle this?
If so, should I create 5 models, 1 per table?
If not, should I create a single ( or 2 ) Models ( Product, Attribute ) and the connect them using custom SQLs and methods?
What are the relations here? Attributes seem to have one-to-many to me, but combinations also seem one-to-many and both of these are also connected to each other.
I'm struggling to understand the relations between the above. It seems understandable via SQL, but I can't relate them to each other via Eloquents.
Also, the tables seems to grow massive rapidly. Is this approach proper at all?
Your approach seems very difficult to maintain in the long term. I don't understand why you would have to separate the name attribute from value.
I would create the product model, size and color with its migrations and a pivot table to store the stock
- size_table
-- id
-- name
- color_table
-- id
-- name
- product_table
-- id
-- type (shirt, pants, pullover ... etc.)
-- description
-- status
- stock_table
-- product_id (reference to the product table)
-- color_id (Reference to the color table)
-- size_id (Reference to the size table)
-- quantity (Quantity of products available with these attributes)
-- status
this way you have the same product with more than one combination stored in stock_table.
Now you only need to define the relationships between each model and then you will be able to access all the attributes from product_detail_table
$item->quantity
$item->product->description
$item->size->name
$item->color->name

TOPN DAX function not working. The formula is returning all the rows and not TOP 3

My goal is to create measure to get top 3 customer Names and there respective sales.
I am using the below measure to bring top 3 names along with there sales. The below measure is returning all the rows. I fail to understand why this is happening and why filtering is not happening for top 3 customers
topN = calculate(sum(Sale[Total Excluding Tax]),
TOPN(3,
values(Sale[Employee Name]),
calculate(sum(Sale[Total Excluding Tax]))
)
)
Sale[Employee Name] is calculated column and is coming from another table Employee by using Employee Name = RELATED(Employee[Employee])
The DAX is working properly and grabbing top 3 records. Order/sorting is important. You need to order your results.
Create a calculate column [Total Excluding Tax] to sum up the Total excluding tax. Then use that column in a measure; try something like:
Top Sales = TOPN ( 3, ALLSELECTED( 'Sale' ), [Total Excluding Tax]), desc)

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.

Resources