Forum Discussion

JustinDoh1's avatar
JustinDoh1
Post Prodigy
5 years ago
Solved

Combine TREATAS with Calculate function

I am sharing Pbix file here in this Google Drive.   Also, please note that I modified the original code and updated code is reflected on this post. So, some of code mentioned on the bottom discuss...
  • Element115's avatar
    Element115
    5 years ago

    No worries.  Did you see my response here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Combine-TREATAS-with-Calculate-function/m-p/1953210/highlight/true#M42622

     

    Basically I commented out your TREATAS and got the results you wanted as per your first post here.

    I do not know what the semantics of your model should be like, but like you said in your last post, there is no direct relationship between the 2 table Main and Index. Even so, it is not necessary to perform your computation, as I have shown in my response at the link above.

     

    Now, if on the other hand, you need some sort of relationship between Main and Index, then use everything you know from SQL re how to design a proper ER diagram.  Those principles translate well to designing a star- or snowflake schema in Power BI.  In fact, it's actually easier to design a star schema with Dim or Lookup tables on top in the modeling space, and the Fact tables underneath the Dim tables.

     

    Fundamentally, if you are gonna have to deal with date and/or time, then you need to make sure  you first create a well-formed DimDate table and/or a DimTime table.  You can do it in M in Power Query Editor, or in DAX. I do it in M usually because that way I can parameterize the table creation.  Google it and you'll find the code for both options online. 

     

    Once you have that, you need to think about the semantic relationship between you data and that will help come up with the Fact tables and what the relationships among them should be. And so on.