Forum Discussion

pk1593's avatar
pk1593
Helper I
3 years ago

Tableau to DAX code

Can anyone help in converting this code to DAX?


S =
ABS([x]-LOOKUP([x],-1))/
(
SQRT
(
ABS(((([y] + LOOKUP([y],-1))/(SUM([z])+LOOKUP(SUM([z]), - 1)])))
*
(1-(([y] + LOOKUP([y],-1))/(SUM([z])+ LOOKUP(SUM([z]),-1)))))/ (1-((1/(SUM([z])+LOOKUP(SUM([z]),-1))))))
*
(1/SUM([z]) + 1/LOOKUP(SUM[z]),-1))
)
)

6 Replies

  • ValtteriN's avatar
    ValtteriN
    Community Champion

    Hi, 

    For converting Tableau to DAX try utilizing ChatGPT. It works fast and provides answers like this:

    S = ABS([x] - LOOKUPVALUE([x], -1)) / (SQRT(ABS( (([y] + LOOKUPVALUE([y], -1)) / (SUM([z]) + LOOKUPVALUE(SUM([z]), -1))) * (1 - (([y] + LOOKUPVALUE([y], -1)) / (SUM([z]) + LOOKUPVALUE(SUM([z]), -1)))) ) / (1 - ((1 / (SUM([z]) + LOOKUPVALUE(SUM([z]), -1)))))) * (1 / SUM([z]) + 1 / LOOKUPVALUE(SUM([z]), -1)))

    You can also replace / with DIVIDE to avoid issues with 0. For the [x], [y] and [z] use the corresponding column refrerences.

    I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

    My LinkedIn: https://www.linkedin.com/in/n%C3%A4ttiahov-00001/

    • pk1593's avatar
      pk1593
      Helper I

      No this is incorrect. 
      I tried chatGPT but lookupvalue syntax is wrong and not a substitute for Lookup in Tableau. 

      • ValtteriN's avatar
        ValtteriN
        Community Champion

        I see, sorry about that. I just read the LOOKUP documentation in Tableau. The dax equivalent for LOOKUP would be OFFSET

  • v-zhangti's avatar
    v-zhangti
    Community Support

    Hi, pk1593 

     

    Can you provide sample data for testing? Sensitive information can be removed in advance. What kind of expected results do you expect? You can also show it with pictures or Excel. I look forward to your response.

     

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • pk1593's avatar
      pk1593
      Helper I

       Here S (col. highlighted in yellow) is the desired result which ia the significance t-testing forumula.
      The table has 3 data points from 2019 to 2021. 
      x is in percentage, whereas y and z are weigted and unweighted counts of respective years. 

      • pk1593's avatar
        pk1593
        Helper I

        v-zhangti - Just wanted to check if you were able to convert the Tableau code to DAX ?