How to filter SUMMARIZECOLUMNS after crossjoin - filter

I am trying to filter the SUMMARIZECOLUMNS by using the CALCULATETABLE, it prompted me an error message:
"SummarizeColumns can not have outside filter context"
Is it because of SSAS version, my version is: 13.0.2213.0
EVALUATE
CALCULATETABLE(
SUMMARIZECOLUMNS(
'Product'[Model Name],
'Product'[Product Line],
'Product'[Product Name],
'Customer'[First Name],
'Customer'[Last Name],
"Internet Current Quarter Sales", [Internet Current Quarter Sales],
"Internet Total Sales", [Internet Total Sales]
),
'Internet Sales'[Order Date] > DATEVALUE("1 Jan 2011"),
OR('Geography'[Country Region Name] = "Australia", 'Geography'[Country Region Name] = "United States")
)
ORDER BY 'Product'[Model Name]
I can filter by put the FILTER function inside SUMMARIZECOLUMNS, however it gave me a different result (less records than expected) as the table was filtered before corss-join: https://learn.microsoft.com/en-us/dax/summarizecolumns-function-dax
EVALUATE
SUMMARIZECOLUMNS(
'Product'[Model Name],
'Product'[Product Line],
'Product'[Product Name],
'Customer'[First Name],
'Customer'[Last Name],
FILTER('Internet Sales', [Order Date] > DATEVALUE("1 Jan 2011")),
FILTER('Geography', [Country Region Name] = "Australia" || [Country Region Name] = "United States"),
"Internet Current Quarter Sales", [Internet Current Quarter Sales],
"Internet Total Sales", [Internet Total Sales]
)
ORDER BY 'Product'[Model Name]
filterTable:
A table expression which is added to the filter context of all columns specified as groupBy_columnName arguments. The values present in the filter table are used to filter before cross-join/auto-exist is performed.
Any idea how to achive the filter same as CALCULATETABLE function? Thank you.

Related

DAX: Removing a filter for a measure in the SUMMARIZECOLUMNS query

I'm struggling to create a DAX query to get the weekly sales amount and total sales amount (sum of all weeks together) on a same row. I'm filtering on item and year.
Example of a query:
EVALUATE
SUMMARIZECOLUMNS(
Artikel[ART Artikel],
Datum[Jahr-Woche],
FILTER (
Artikel,
Artikel[ART ArtikelNr]="222834"
),
FILTER (
'Datum',
Datum[Jahr]="2022"
),
"Sales Quantity ", [VK Menge],
"Sales Quantity Total", CALCULATE([VK Menge], ALL(Datum[Jahr-Woche]) )
)
The Sales Quantity Total doesn't return the yearly total - it returns the same value as Sales Quantity. It seems that the ALL() function is not removing the filter from the column Datum[Jahr-Woche]):
I've tried using REMOVEFILTERS(), etc. to no success.
What am I doing wrong?
Note 1:
When I remove the filtering on Datum[Jahr] from the query, the ALL() function starts working - the Sales Quantity Total returns the total sum. However - I need to filter on the year in the query... This behaviour is very confusing. :(
EVALUATE
SUMMARIZECOLUMNS(
Artikel[ART Artikel],
Datum[Jahr-Woche],
FILTER (
Artikel,
Artikel[ART ArtikelNr]="222834"
),
"Sales Quantity ", [VK Menge],
"Sales Quantity Total", CALCULATE([VK Menge], ALL(Datum[Jahr-Woche]) )
)
Please try this code and let me know If It works for you! Calculate evaluates external filters first, then internal filters!
YourMeasure =
SUMMARIZECOLUMNS (
Artikel[ART Artikel],
Datum[Jahr-Woche],
FILTER ( Artikel, Artikel[ART ArtikelNr] = "222834" ),
"Sales Quantity ", [VK Menge],
"Sales Quantity Total",
CALCULATE (
CALCULATE ( [VK Menge], Datum[Jahr] = "2022" ),
ALL ( Datum[Jahr-Woche] )
)
)
EXPLAIN Above Same Code:

PowerBi - How to show multiple total columns in Matrix?

I have a slicer from which I can select weeks that I want to show on a matrix. Currently, the matrix only shows the total column at the end of all columns basically summing up all the values.
But I want to show multiple total column (One after each month). Like after the End Of Weeks of one month a total column and so on.
You cannot simply create a Calculated column or Measure to solve this problem. Actually, you can use some logic with Calculated column, but there is a more efficient way. To achieve the goal, you have to create Calculated table based on your date column. You can use that logic to create any custom label for your visuals.
Before we start diving into deep DAX here, let's create a calendar table.
Calendar =
VAR _minSalesDate = CALCULATE( MIN( Sales[Date] ), ALL( Sales ) )
VAR _maxSalesDate = CALCULATE( MAX( Sales[Date] ), ALL( Sales ) )
RETURN
ADDCOLUMNS(
CALENDAR( _minSalesDate, _maxSalesDate ),
"Month", MONTH( [Date] ),
"MonthYear", MONTH( [Date] ) & "-" & YEAR( [Date] )
)
Now, when we have the table with our dates and additional fields, we can start creating a solution for this particular case.
Create a new calculated table as follows:
CustomCategories =
UNION(
SELECTCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[Sorter]
),
"Key", 'Calendar'[Date],
"Label", 'Calendar'[Date],
"LabelSorter", 'Calendar'[Sorter]
),
ADDCOLUMNS(
SELECTCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[MonthYear],
'Calendar'[Sorter]
),
"Key", 'Calendar'[Date],
"Label", 'Calendar'[MonthYear]
),
"LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALLEXCEPT( 'Calendar', 'Calendar'[MonthYear] ) ) + 0.5
),
SELECTCOLUMNS(
ADDCOLUMNS(
SUMMARIZE(
'Calendar',
'Calendar'[Date],
'Calendar'[Sorter]
),
"LabelSorter", CALCULATE( MAX( 'Calendar'[Sorter] ), ALL( 'Calendar' ) ) + 1
),
"Key", 'Calendar'[Date],
"Label", "Total",
"LabelSorter", [LabelSorter]
)
)
Note that the last part of above DAX adding Total is optional.
Once the table has been created, go to the Data view, select CustomCategories table, select Label column and sort the column by LabelSorter (you will find an option on the ribbon). Then go back to your Model view and set a relationship between CustomCategories and your Fact table on Date column.
When you have done with all stuff above, switch back to the Report view. Remove the date column from your table visual and replace it with the newly created Label from CustomCategories table.
Now you should see the desired results.
Hope that helps!
Regards,
Arek

DAX GENERATE & ALLNOBLANKROW functions lead to circular dependency

I'm trying to use a DAX function to generate a table in Power BI. I have a fact table with Opened & Closed date columns and there is a requirement to report at the end of each day/month/year how many items were backlogged.
I've got the table to generate successfully with the code below - essentially joining the date and fact tables, however I can't then link it back to my dimensions due to a circular dependency error.
Researching it online suggests that I need to remove the blank row from fact_task_transaction with the ALLNOBLANKROW function. Unfortunately this has no effect.
Can anyone help?
Backlog Per Day =
var res = SELECTCOLUMNS (
GENERATE (
fact_task_transaction,
FILTER (
ALLNOBLANKROW ( 'Date' ),
AND(
'Date'[Date] >= fact_task_transaction[Opened At Date],
'Date'[Date] <= fact_task_transaction[Closed At Date]
)
)
),
"Date", 'Date'[Date],
"Task ID", fact_task_transaction[Task Id],
"Assignee ID", fact_task_transaction[Assignee Id]
)
return res
try this code - it only uses fact_task_transaction, so the joins with dimensions shuld be working fine
Backlog Per Day =
SELECTCOLUMNS (
GENERATE (
'fact_task_transaction',
GENERATESERIES (
CALCULATE ( MIN ( 'fact_task_transaction'[Opened At Date] ) ),
CALCULATE ( MAX ( 'fact_task_transaction'[Closed At Date] ) ),
1
)
),
"Date", [Value],
"Task ID", fact_task_transaction[Task Id],
"Assignee ID", fact_task_transaction[Assignee Id]
)

DAX - Advanced Product Grouping/Segmentation Question

I created an SSAS Tabular model using the AdventureWorksDW database.
I used the post below to help me build the report.
https://blog.gbrueckl.at/2014/02/applied-basket-analysis-in-power-pivot-using-dax/
Sold in same Order:=
CALCULATE (
COUNTROWS ( 'Internet Sales' ),
CALCULATETABLE (
SUMMARIZE (
'Internet Sales',
'Internet Sales'[SalesOrderNumber]
),
ALL ( 'Product' ) ,
USERELATIONSHIP( 'Internet Sales'[ProductKey],FilteredProduct[ProductKey])
)
)
I have validated that the results from the formula are correct. There are 1,381 orders with the Touring Tire Tube sold and shows me how many orders were sold with the other items (e.g. 170 out of the 1,381 orders also included product key 214 - Sport-100 Helmet, Red).
Here is where I'm having an issue. I would like to summarize my data by showing how many of the orders only included my filtered items vs. orders sold with other products. This has to be dynamic since users can select any products... The end result should look like this:
I'm new to DAX and have struggled with this for a few hours. Thanks for your help.
Here is the table relationship:
this DAX should work on the example dataset from my blog:
Orders with only the filtered products =
--VAR vFilteredProducts = VALUES('Filtered Product'[ProductKey])
VAR vFilteredProducts = FILTER('Filtered Product', [ProductKey] = 530 || [ProductKey] = 541)
VAR vCountFilteredProducts = COUNTROWS(vFilteredProducts)
VAR vSales = CALCULATETABLE('Internet Sales', -- get the Sales for the filtered Products
vFilteredProducts,
USERELATIONSHIP('Filtered Product'[ProductKey], 'Internet Sales'[ProductKey]),
ALL('Product'))
VAR vOrders = SUMMARIZE( -- Summarize the filtered product sales by Sales Order Number
vSales,
[Sales Order Number],
-- calucate the distinct filtered products in the filtered orders
"CountFilteredProductsInOrder", CALCULATE(DISTINCTCOUNT('Internet Sales'[ProductKey])),
-- calculate the all distinct products for the filtered orders
"CountTotalProductsInOrder", CALCULATE(DISTINCTCOUNT('Internet Sales'[ProductKey]),
ALLEXCEPT('Internet Sales', 'Internet Sales'[Sales Order Number]))
)
RETURN COUNTROWS(
FILTER(
vOrders,
-- the total product count has to match the filtered product count --> no other products except filtered ones in order
[CountFilteredProductsInOrder] = [CountTotalProductsInOrder]
)
)
To get the orders where also other products except the filtered ones were sold, imply change the last FILTER() from '=' to '<'

dax studio - Filtering Data

Using DAX studio, I'm trying to understand what data this filter function is pulling.
EVALUATE
FILTER ( 'TM Freight Charges',
'TM Freight Charges'[Related Order Type] = Fact_Table[Order Type])
However, I get the following error message:
error message image
ultimately, I'm trying to evaluate this particular filter formula
Evaluate
FILTER ('TM Freight Charges',
AND (
AND (
AND (
'TM Freight Charges'[Related Order Type] = [Order Type],
'TM Freight Charges'[Related Order Number] = [Order Number]
),
'TM Freight Charges'[Volume] = Fact_Table[Volume]
),
'TM Freight Charges'[Charge Type] = "BASE"
)
)
)
If this was a SQL problem, I would just do an INNER JOIN along with some WHERE statements, but in DAX Studio, I don't have a clue. Help?
If you specify an 'equal' on the filter, you should pass a value or a list or something. If you are doing that on a row context (for example adding a column to a table), the way you did it will work, but on building a table there's no context for that. Did you try something like:
EVALUATE
FILTER ( 'TM Freight Charges',
'TM Freight Charges'[Related Order Type] IN Fact_Table[Order Type])
or:
EVALUATE
FILTER ( 'TM Freight Charges',
'TM Freight Charges'[Related Order Type] IN VALUES ( Fact_Table[Order Type]) )
Cheers!

Resources