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
AshDil
Helper V
Helper V

YTD values showing Blanks for missing ID

Hi,

I have two tables

Table-1:

IDDATESALES
10011/1/20222000
10012/1/20223200
10014/1/20222220
10016/1/20221500
10022/1/20224000
10023/1/20223000
10024/1/2022900

Table -2:

IDDATETARGET
10011/1/20221000
10012/1/20223000
10013/1/20222000
10014/1/20221500
10015/1/20225000
10016/1/20222000
10021/1/20223400
10022/1/20222300
10023/1/20224000
10024/1/20223000
10025/1/20222000
10026/1/20225000

Year and Month slicers are present for Visual.

In Slicers Year = 2022 and Month = 3 are selected. I wanted to show for ID = 1001, "YTD Sales Vs YTD Targets" = 5200/6000 = 86.7%

I tried to do it with following calculation

YTD SALES VS YTD TARGET =
VAR _Target = CALCULATE(YTD TARGET,TARGET[ID] IN VALUES(SALES[ID]))
RETURN
DIVIDE([YTDSALES],_Target)
But getting blank for ID = 1001 with above calculation as it is missing in March.
Please help me to do it.
 
Thanks,
AshDil
2 ACCEPTED SOLUTIONS
amitchandak
Super User
Super User

@AshDil , Create a common ID and Date table

ID = distinct(Union(Distinct(Table1[ID]), Distinct(Table2[ID]) ) )

 

Create a date table using a calendar and the use ID from the ID table and Date from the date table filter

 

example of YTD
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

View solution in original post

v-chenwuz-msft
Community Support
Community Support

Hi @AshDil ,

 

First, you need create Date Table which has no relationship with Fact table1 and table2. Then create a dim table of ID via 

ID = DISTINCT( UNION(VALUES('Table-1'[ID]),VALUES('Table-2'[ID])))
Or import a table. And create relationship between fact table1 and 2 with this ID table as the following screenshot.
 

vchenwuzmsft_0-1655974367330.png


The fields of the slicer year and month both comes from Date table.

 

At last, the calculate measure like this:

 

Measure =
VAR _date =
    EOMONTH ( MAX ( 'Table'[Date] ), 0 )
VAR _sale =
    CALCULATE (
        SUM ( 'Table-1'[SALES] ),
        DATESBETWEEN ( 'Table-1'[DATE], DATE ( YEAR ( _date ), 1, 1 ), _date )
    ) + 0
VAR _target =
    CALCULATE (
        SUM ( 'Table-2'[TARGET] ),
        DATESBETWEEN ( 'Table-2'[DATE], DATE ( YEAR ( _date ), 1, 1 ), _date )
    )
RETURN
    DIVIDE ( _sale, _target )

 

Result:

vchenwuzmsft_1-1655974377871.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

View solution in original post

3 REPLIES 3
v-chenwuz-msft
Community Support
Community Support

Hi @AshDil ,

 

First, you need create Date Table which has no relationship with Fact table1 and table2. Then create a dim table of ID via 

ID = DISTINCT( UNION(VALUES('Table-1'[ID]),VALUES('Table-2'[ID])))
Or import a table. And create relationship between fact table1 and 2 with this ID table as the following screenshot.
 

vchenwuzmsft_0-1655974367330.png


The fields of the slicer year and month both comes from Date table.

 

At last, the calculate measure like this:

 

Measure =
VAR _date =
    EOMONTH ( MAX ( 'Table'[Date] ), 0 )
VAR _sale =
    CALCULATE (
        SUM ( 'Table-1'[SALES] ),
        DATESBETWEEN ( 'Table-1'[DATE], DATE ( YEAR ( _date ), 1, 1 ), _date )
    ) + 0
VAR _target =
    CALCULATE (
        SUM ( 'Table-2'[TARGET] ),
        DATESBETWEEN ( 'Table-2'[DATE], DATE ( YEAR ( _date ), 1, 1 ), _date )
    )
RETURN
    DIVIDE ( _sale, _target )

 

Result:

vchenwuzmsft_1-1655974377871.png

 

Pbix in the end you can refer.

Best Regards

Community Support Team _ chenwu zhu

 

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

amitchandak
Super User
Super User

@AshDil , Create a common ID and Date table

ID = distinct(Union(Distinct(Table1[ID]), Distinct(Table2[ID]) ) )

 

Create a date table using a calendar and the use ID from the ID table and Date from the date table filter

 

example of YTD
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

 

Power BI — Year on Year with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-ytd-questions-time-intelligence-1-5-e3174b39f38a
https://www.youtube.com/watch?v=km41KfM_0uA

amitchandak
Super User
Super User

@AshDil , Create a common ID and Date table

ID = distinct(Union(Distinct(Table1[ID]), Distinct(Table2[ID]) ) )

 

Create a date table using a calendar and the use ID from the ID table and Date from the date table filter

 

example of YTD
YTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESYTD('Date'[Date],"12/31"))

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