Window function - unique ranking

NateBI
NateBI Member
edited January 2023 in Magic ETL

Hi all,

I'm trying to create the following logic for column '?' based on the header column:

context

header: the original column I want to rank against

temp: a constant 1 for the row number logic

row number: a row number ordered by temp ascending (recommended on the forum)

header identifier: a conditional column using 'CASE WHEN [columnA] = 'Market' THEN 'START' END'

Currently trying a rank & window using rank-ordered by the 'row number' and partitioned by the header identifier but at the point of 'START' it removes that row, the row count skips and the rank & window output works as a row number.

All support appreciated

Best Answers

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Try using a formula tile to set the value of a column to be 1 if it's = 'market' and 0 if it's not (or whatever logic you need to mark it as the start). Then use the rank & window to do a running total of the column.

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • GrantSmith
    GrantSmith Coach
    Answer ✓

    You wouldn't want to order by your header as that'd have all the 0s first then the 1s so likely your row is at the end of your dataset.

    Try sorting based on your Row_Number field instead.

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**

Answers

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    Try using a formula tile to set the value of a column to be 1 if it's = 'market' and 0 if it's not (or whatever logic you need to mark it as the start). Then use the rank & window to do a running total of the column.

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • NateBI
    NateBI Member
    edited January 2023

    @GrantSmith

    Thanks for the response, this seems to display a similar issue removing the row:


    Running total settings:

    Before running total applied:


    After applied



    Any thoughts?

  • GrantSmith
    GrantSmith Coach
    Answer ✓

    You wouldn't want to order by your header as that'd have all the 0s first then the 1s so likely your row is at the end of your dataset.

    Try sorting based on your Row_Number field instead.

    **Was this post helpful? Click Agree or Like below**
    **Did this solve your problem? Accept it as a solution!**
  • @GrantSmith Thanks this worked -- Ordered by the Row Number. Perfect thank you!