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
mkjit256
Advocate I
Advocate I

DAX question: How to calculate YTD of the ratio of two measures.

Hello everyone.
Consider the following scenario:
I have two fact tables, where i am building two measures A & B such that:

A = Calculate(sum(Table1[Column1])
B = Calculate(Count(Table2[ColumnA]), Table2[ColumnB]="ValueB", Table2[ColumnC] = "ValueC")


I have also defined a measure C as:

 

 

 

 

 

 

 

 

 

C =  if(B>1000000 , DIVIDE(A*1000000,B), DIVIDE(A*100000,B))

 

 

 

 

 

 

 

 

and has visualized the results in a Matrix Visual.

mkjit256_0-1706798860781.png

 

The problem that i am having begins when i try to calculate the  YTD of measure C, as follows:

 

 

 

 

 

 

 

 

YTD_C = TOTALYTD(C,Date[Date])

 

 

 

 

 

 

mkjit256_1-1706798884348.png

 


What is actually happening in YTD_C is Sum(A_i)/Sum(B_i) instead of sum(A_i/B_i)

For example the YTD_C for 2013 -03-01 currently calculated is (A1+A2+A3)/(B1+B2+B3) but what i am looking to have is:
(A1/B1 + A2/B2 + A3/B3)

how can i achieve that? 

@Greg_Deckler, any guidnance or thoughts would be really appreciated.

4 REPLIES 4
Dangar332
Super User
Super User

 

 

hi, @mkjit256 

 

try below measure

 

 

measure=
CALCULATE(
   [c],
   DATESYTD('date'[date]),
   ALLEXCEPT('date','date'[date])
 )

Thanks for your reply. It is giving the same thing as the YTD_C

YTD_C = TOTALYTD(C,Date[Date])

 

Jihwan_Kim
Super User
Super User

Hi,

I am not sure how your semantic model looks like, but please try something like below.

 

expected result measure: =
SUMX (
    WINDOW (
        1,
        abs,
        0,
        rel,
        ALL ( CalendarTable ),
        ORDERBY ( CalendarTable[datecolumn], ASC ),
        ,
        PARTITIONBY ( CalendarTable[year] )
    ),
    measure_C
)

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


Hello Kim,

Thanks for your reply, the scemantic layer that i am using is very simple,

mkjit256_0-1706880766227.png

Table A and B are my fact tables, and i have some additional dimension tables that are all in 1 to many relationship with the fact tables.

I have tried the measure that you have provided but it is not giving what i am expecting, and i am explain the numbers. here is what i am getting.

mkjit256_1-1706881465483.png

 

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.

Top Solution Authors