Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
Anonymous
Not applicable

SQL query to DAX Measure conversion

I have the following SQL query that I have converted to DAX Measure

 

SELECT
 RowNumber = ROW_NUMBER() OVER (PARTITION BY SSN ORDER BY EOMDate DESC)
FROM [TransArchive].dbo.AGGR_Transaction_ChannelUtilization
WHERE EOMDate BETWEEN @dteEOMBegin AND @dteEOMEnd

 

 

DAX Measure :::

Index = CALCULATE(COUNTROWS('Member Channel Utilization'), FILTER(ALLSELECTED ('Member Channel Utilization')
,FILTER('Member Channel Utilization','Member Channel Utilization'[Report Date]<= EARLIER('Member Channel Utilization'[Report Date]))
,FILTER('Member Channel Utilization','Member Channel Utilization'[EDWCustomerID]= EARLIER('Member Channel Utilization'[EDWCustomerID]))))
 
Please Note :::: ReportDate = EOMdate  and SSN =EDWCustomerID
I have used ALLSELECTED becasue I want the rownum value to change based on the date range filter and /or any other filter selected by the user on the PowerBI report. When I run the query I get the following message "Too Many Arguments were passed to the FILTER Function. The Maximum argument count for the function is 2"....
Could you please let me know how to make this DAX work . Thanks in advance
4 REPLIES 4
selimovd
Super User
Super User

Hey @Anonymous ,

 

it's not possible to nest FILTER functions. Just combine in one filter what you want to filter.

I guess you wanted something like this:

Index =
CALCULATE(
    COUNTROWS( 'Member Channel Utilization' ),
    FILTER(
        ALLSELECTED( 'Member Channel Utilization' ),
        'Member Channel Utilization'[Report Date] <= EARLIER( 'Member Channel Utilization'[Report Date] ) && 'Member Channel Utilization'[EDWCustomerID] = EARLIER( 'Member Channel Utilization'[EDWCustomerID] )
    )
)

 

If you need any help please let me know.
If I answered your question I would be happy if you could mark my post as a solution ✔️ and give it a thumbs up 👍
 
Best regards
Denis
 
Anonymous
Not applicable

Thanks @selimovd 

I have actually Succesfully created the Index column Measure now .....But now I want to use this measure to create a New Measure Marker Column ....expected result is something like this 

Report Date EDWCustomerID Index Marker
8/31/2020 0:00 3 1 0
9/30/2020 0:00 3 2 0
10/31/2020 0:00 3 3 0
11/30/2020 0:00 3 4 0
4/30/2021 0:00 3 5 1
8/31/2020 0:00 4 1 0
9/30/2020 0:00 4 2 0
10/31/2020 0:00 4 3 0
11/30/2020 0:00 4 4 0
4/30/2021 0:00 4 5 1
8/31/2020 0:00 5 1 0
9/30/2020 0:00 5 2 0
10/31/2020 0:00 5 3 0
11/30/2020 0:00 5 4 0
4/30/2021 0:00 5 5 1

 

Here I want to mark the row with max value in the Index column per Reporte Date per EDWCustomerid

Hopefully this makes sense. Thanks in advance.

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("bY9LCsAgDETvkrWQxDFgzyLe/xottUhwun3MdwxxU7hWqyZFmsxyICzkCjtUGcWL2kd8+zJZtouCemoL0gRP4rKgIFDQzxGQ7Vk0bw==", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [#"Report Date" = _t, EDWCustomerID = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Report Date", type date}, {"EDWCustomerID", Int64.Type}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"EDWCustomerID"}, {{"ar", each let t = Table.AddIndexColumn(Table.Sort(_, {"Report Date", Order.Ascending}),"Index",1,1), max = List.Max(t[Index]) in Table.AddColumn(t, "Marker", each if [Index]=max then 1 else 0)}}),
    #"Expanded ar" = Table.ExpandTableColumn(#"Grouped Rows", "ar", {"Report Date", "Index", "Marker"}, {"Report Date", "Index", "Marker"})
in
    #"Expanded ar"

Screenshot 2021-08-17 093541.png

 


Thanks to the great efforts by MS engineers to simplify syntax of DAX! Most beginners are SUCCESSFULLY MISLED to think that they could easily master DAX; but it turns out that the intricacy of the most frequently used RANKX() is still way beyond their comprehension!

DAX is simple, but NOT EASY!

Anonymous
Not applicable

Thanks for the resposne @CNENFRNL 
I need a DAX measure for this becasue my Dates change dynamically 

 

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.