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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
ny326n
Frequent Visitor

How to make an array formula in DAX?

Hello!

 

Earlier I've created a formula in Excel which I now want to translate into DAX, but can't manage to figure out how. 

 

I have a table with all sales and these are some of colums:

Assignment ID

Assignment creation date and time

Creator user ID

 

What I want to create is a new column saying if the sales row is new or resale. So the fist time a Creator user ID appears it should say new and the next time it should say resale. In excel this was solved by this formula: 

{=IF(MIN(IF(E2=$E$2:$E$816;$B$2:$B$816))=B2;"New";"Resale")}

E being Creator user ID 

B being Assignment creation date and time

 

How can this be done in Power BI desktop?

 

Hope this explenation makes sense! Many thanks!

1 ACCEPTED SOLUTION
v-ljerr-msft
Employee
Employee

Hi @ny326n,

 

Based on my test, the formula below should also work in your scenario. Smiley Happy

Column =
IF (
    Data[Date and Time]
        = CALCULATE (
            MIN ( Data[Date and Time] ),
            FILTER (
                ALL ( Data ),
                Data[Creator User ID] = EARLIER ( Data[Creator User ID] )
            )
        ),
    "New",
    "Resale"
)

c3.PNG

 

Regards

View solution in original post

5 REPLIES 5
v-ljerr-msft
Employee
Employee

Hi @ny326n,

 

Based on my test, the formula below should also work in your scenario. Smiley Happy

Column =
IF (
    Data[Date and Time]
        = CALCULATE (
            MIN ( Data[Date and Time] ),
            FILTER (
                ALL ( Data ),
                Data[Creator User ID] = EARLIER ( Data[Creator User ID] )
            )
        ),
    "New",
    "Resale"
)

c3.PNG

 

Regards

HI, @v-ljerr-msft

 

Awesome solution, I had the same issue finally seen your post and got resolved. 🙂 

 

 

HI, @v-ljerr-msft

 

Awesome solution, I had the same issue finally seen your post and got resolved. 🙂 

 

 

Anonymous
Not applicable

You can also consider using M (Power Query). See this solution: https://community.powerbi.com/t5/Desktop/Custom-column-Index-or-Ranking-by-other-column/td-p/33864.

Anonymous
Not applicable

You can try to use RANKX and EARLIER functions in DAX. Example:

 

  1. Let's assume you have the following data (table named Data):

    Creator User IDDate and TimeAssignment ID
    12017-01-01 12:001
    22017-01-01 12:002
    12017-02-01 12:003
    22017-02-01 12:004
  2. Add new Calculated Column:

    New/Resale = IF(
    RANKX(
    FILTER(Data;EARLIER(Data[Creator User ID])=Data[Creator User ID]);
    Data[Date and Time];;
    ASC;
    Dense
    ) = 1;
    "New";
    "Resale"
    )


Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.