Starting December 3, join live sessions with database experts and the Microsoft product team to learn just how easy it is to get started
Learn moreGet certified in Microsoft Fabric—for free! For a limited time, get a free DP-600 exam voucher to use by the end of 2024. Register now
I am writing an SSRS report based on DAX. I am not sure if this is possible or not.
I have several parameters for the report that are passed as id's using the below pattern which work fine.
VAR __CompanyPS =
SUBSTITUTE ( @CompanyDDS, ",", "|" )
then in the summarizecolumns filter
FILTER (
ALL ( Company[Company Id] ),
PATHCONTAINS ( _CompanyPS, Company[Company Id] )
)
I also want a parameter in the report that allows people to enter sku names or better still parts of sku names to filter as well.
There may be a SKUs called ABC123, ABC456, DEF123. The person could enter "ABC" and that would filter skus with ABC.
I can use ContainRows but that is only on exact matches no string searches as below.
DEFINE
VAR _SkuPS =
SUBSTITUTE ( "ABC123,ABC456", ",", "|" )
VAR _SkuTable =
SELECTCOLUMNS (
GENERATESERIES ( 1, _len ),
"Skus", PATHITEM ( _skuPS, [value], TEXT )
)
EVALUATE
FILTER (
ALL ( Products[sku], Products[Product Id] ),
CONTAINSROW ( _skutable, Products[SKU] )
)
it would be really nice to be able to allow multiple string searches as well as actual skus but I can't see how I could do this.
Solved! Go to Solution.
Hello @gooranga1,
Can you please try this approach to filter with multiple substrings:
DEFINE
VAR __CompanyPS = SUBSTITUTE(@CompanyDDS, ",", "|")
VAR __SkuParam = SUBSTITUTE(@SkuDDS, ",", "|")
VAR __SkuPatterns =
ADDCOLUMNS(
GENERATESERIES(1, PATHLENGTH(__SkuParam)),
"Pattern", PATHITEM(__SkuParam, [Value], TEXT)
)
VAR __MatchingSkus =
FILTER(
ALL(Products[SKU]),
SUMX(
__SkuPatterns,
IF(CONTAINSSTRING(Products[SKU], [Pattern]), 1, 0)
) > 0
)
VAR __FilteredTable =
CALCULATETABLE(
SUMMARIZECOLUMNS(
Company[Company Id],
Products[SKU],
Products[Product Id],
FILTER(
ALL(Company[Company Id]),
PATHCONTAINS(__CompanyPS, Company[Company Id])
)
),
__MatchingSkus
)
EVALUATE __FilteredTable
Hope this helps.
thanks @Sahir_Maharaj that has worked!
DAX doesn't seem to be as flexible as SQL in filtering these. It would be optimal to have functionality like;
SELECT sku
FROM Products as P
where p.sku like 'ABC%'
filtering skus that start with 'ABC' only rather than ABC occuring anywhere in the text string. The wildcard characters in DAX don't seem to work in the same way as SQL.
but this solution is definitely good enough for my purposes now.
Hello @gooranga1,
Can you please try this approach to filter with multiple substrings:
DEFINE
VAR __CompanyPS = SUBSTITUTE(@CompanyDDS, ",", "|")
VAR __SkuParam = SUBSTITUTE(@SkuDDS, ",", "|")
VAR __SkuPatterns =
ADDCOLUMNS(
GENERATESERIES(1, PATHLENGTH(__SkuParam)),
"Pattern", PATHITEM(__SkuParam, [Value], TEXT)
)
VAR __MatchingSkus =
FILTER(
ALL(Products[SKU]),
SUMX(
__SkuPatterns,
IF(CONTAINSSTRING(Products[SKU], [Pattern]), 1, 0)
) > 0
)
VAR __FilteredTable =
CALCULATETABLE(
SUMMARIZECOLUMNS(
Company[Company Id],
Products[SKU],
Products[Product Id],
FILTER(
ALL(Company[Company Id]),
PATHCONTAINS(__CompanyPS, Company[Company Id])
)
),
__MatchingSkus
)
EVALUATE __FilteredTable
Hope this helps.
Starting December 3, join live sessions with database experts and the Fabric product team to learn just how easy it is to get started.
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early Bird pricing ends December 9th.
User | Count |
---|---|
92 | |
86 | |
85 | |
67 | |
49 |
User | Count |
---|---|
140 | |
113 | |
104 | |
64 | |
60 |