最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

powerbi - Measure if value in 1st table , then specific calculation in 2nd - Stack Overflow

programmeradmin0浏览0评论

Looking for your expertise. Stuck on the 1 measure.

Given: I have 2 tables.

  • Table 1 contains unique country name and status ("running" or "completed").
  • Table 2 contains facts country name (with repetitions) and dates (created and modified) I need to use

Idea is to have measure that will show:

If in Table 1:

  • Country, status = Running, then Table 2: date today - min created
  • Country, status = Completed, then Table 2: max modified - min created

I came up with following dax, but it is not working

CampaignDuration = 

var running_days = -DATEDIFF(TODAY(),MIN('Table2'[Created]),WEEK)

var closed_days = -DATEDIFF(MAX('COI_Merged_All'[Modified]),MIN('Table2'[Created]),WEEK)

VAR Campaign_Status = MAX('Table1'[status])

var result = 
IF(Campaign_Status = "Completed", 
"completed in" & " " & closed_days & " " & "weeks", 
"ongoing" & " " & running_days & " " & "weeks")

RETURN

result

Many thanks in advance for your support

Table 1 | Country | Status | | ------- | --------- | | Spain | Running | | UK | Completed |

Table 2 | Country | Created | Modified | | ------- | ------------- | ----------- | | Spain | 01.01.2024 | 04.01.2024 | | Spain | 02.01.2024 | 05.01.2024 | | Spain | 03.01.2024 | 06.01.2024 | | UK | 01.01.2024 | 03.01.2024 | | UK | 02.01.2024 | 04.01.2024 |

Today - 10.01.2024

Expected result:

  1. Spain selected - 10.01.2024 - 01.01.2024 = 9 days campaign ongoing
  2. UK selected - 04.01.2024 - 01.01.2024 = done in 3 days

Looking for your expertise. Stuck on the 1 measure.

Given: I have 2 tables.

  • Table 1 contains unique country name and status ("running" or "completed").
  • Table 2 contains facts country name (with repetitions) and dates (created and modified) I need to use

Idea is to have measure that will show:

If in Table 1:

  • Country, status = Running, then Table 2: date today - min created
  • Country, status = Completed, then Table 2: max modified - min created

I came up with following dax, but it is not working

CampaignDuration = 

var running_days = -DATEDIFF(TODAY(),MIN('Table2'[Created]),WEEK)

var closed_days = -DATEDIFF(MAX('COI_Merged_All'[Modified]),MIN('Table2'[Created]),WEEK)

VAR Campaign_Status = MAX('Table1'[status])

var result = 
IF(Campaign_Status = "Completed", 
"completed in" & " " & closed_days & " " & "weeks", 
"ongoing" & " " & running_days & " " & "weeks")

RETURN

result

Many thanks in advance for your support

Table 1 | Country | Status | | ------- | --------- | | Spain | Running | | UK | Completed |

Table 2 | Country | Created | Modified | | ------- | ------------- | ----------- | | Spain | 01.01.2024 | 04.01.2024 | | Spain | 02.01.2024 | 05.01.2024 | | Spain | 03.01.2024 | 06.01.2024 | | UK | 01.01.2024 | 03.01.2024 | | UK | 02.01.2024 | 04.01.2024 |

Today - 10.01.2024

Expected result:

  1. Spain selected - 10.01.2024 - 01.01.2024 = 9 days campaign ongoing
  2. UK selected - 04.01.2024 - 01.01.2024 = done in 3 days
Share Improve this question edited 2 days ago Denys asked Feb 6 at 14:03 DenysDenys 33 bronze badges 2
  • could you pls provide some sample data and expected output? – Ryan Commented 2 days ago
  • thnaks, i added details in post – Denys Commented 2 days ago
Add a comment  | 

1 Answer 1

Reset to default 0

you can try to create relationship between two tables

then create a measure

MEASURE =
IF (
    MAX ( 'Table 1'[Status] ) = "Running",
    DATEDIFF ( MIN ( 'Table 2'[Created] ), DATE ( 2024, 1, 10 ), DAY ),
    IF (
        MAX ( 'Table 1'[Status] ) = "Completed",
        DATEDIFF ( MIN ( 'Table 2'[Created] ), MAX ( 'Table 2'[Modified] ), DAY )
    )
)

in your real data, you can change DATE ( 2024, 1, 10 ) to today()

发布评论

评论列表(0)

  1. 暂无评论