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
IF
Post Prodigy
Post Prodigy

Data in different rows

Hi,

I am using a data source that is not really designed in a good way. I have slicers for the month, type, and name. Score 3 is calculated by Score1/Score2. For example; Name=A, Month=7.2022 should provide the score 1/24. As you can see from the example data, they are not in the same row and I don't know how to make them one row or calculate Score3.

 

NameMonthTypeScore1Score2Score3
A7.2022initial 1Score1/Score2
A7.2022#24 Score1/Score3
A8.2022second 2Score1/Score4
A8.2022#34 Score1/Score5
B7.2022initial 1Score1/Score6
B7.2022#43 Score1/Score7
B8.2022last 3Score1/Score8
B8.2022#50 Score1/Score9

Thanks in advance.

1 ACCEPTED SOLUTION

Hi @IF ,

 

I think the easiest fix is to also check the "#" in the slicer as shown in the image below:

vyadongfmsft_0-1663811769098.png

 

Best regards,

Yadong Fang

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

9 REPLIES 9
v-yadongf-msft
Community Support
Community Support

Hi @IF ,

 

OK, please create a measure:

 

New_score3 = IF(ISINSCOPE('Table'[Name]),MAX('Table'[score3]),SUM('Table'[Score2]) &"/"& SUM('Table'[Score1]))

 

vyadongfmsft_0-1663745761872.pngvyadongfmsft_1-1663745788978.png

Best regards,

Yadong Fang

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

I really appreciate for your help and time. This time date and name is working but the "type" slicer is not bringing the result. regards,

25.jpg

Hi @IF ,

 

I think the easiest fix is to also check the "#" in the slicer as shown in the image below:

vyadongfmsft_0-1663811769098.png

 

Best regards,

Yadong Fang

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

v-yadongf-msft
Community Support
Community Support

Hi @IF ,

 

Please create an index column in Power Query:

vyadongfmsft_0-1663661585946.png

 

Please try following DAX to create new columns:

 

New score1 = 
var cur_index = 'Table'[Index]
var pre_index = 'Table'[Index] + 1
var pre_value = CALCULATE(
    MAX('Table'[Score1]),
    FILTER('Table','Table'[Index] = pre_index)
)
return 
IF('Table'[Score1] = BLANK(),pre_value,'Table'[Score1])


New score2 = 
var cur_index = 'Table'[Index]
var pre_index = 'Table'[Index] - 1
var pre_value = CALCULATE(
    MAX('Table'[Score2]),
    FILTER('Table','Table'[Index] = pre_index)
)
return 
IF('Table'[Score2] = BLANK(),pre_value,'Table'[Score2])

Score3 = 'Table'[New score2] &"/"& 'Table'[New score1]

 

vyadongfmsft_1-1663661709114.png

 

You will get result you want:

vyadongfmsft_2-1663661731849.png

 

 

Best regards,

Yadong Fang

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

Hi,

Thanks for the reply. I tried and noticed that I have some cases with more than 2 types. I added 3 more rows to the sample. For example, Name=B, date=8.2022 has initial (4), second (2) and last (3). In this case the score should be 4/50 for initial type, 2/50 for the second type and 3/50 for the last type. Most of the data has only one type, but some of them having 2 or 3 types. Thanks again. 

 

NameMonthTypeScore1Score2Score3
A7.2022initial 1Score1/Score2
A7.2022#24 Score1/Score2
A7.2022initial 2Score1/Score2
A8.2022second 2Score1/Score2
A8.2022#34 Score1/Score2
B7.2022initial 1Score1/Score2
B7.2022#43 Score1/Score2
B8.2022initial 4Score1/Score2
B8.2022second 2Score1/Score2
B8.2022last 3Score1/Score2
B8.2022#50 Score1/Score2

 

Hi @IF ,

 

Please try following DAX:

score3 = 
var cur_score1 = CALCULATE(MAX('Table'[Score1]),FILTER('Table','Table'[Type] = "#" && 'Table'[Month] = EARLIER('Table'[Month]) && 'Table'[Name] = EARLIER('Table'[Name])))
VAR newscore1 = IF('Table'[Score1] = BLANK(),cur_score1)
RETURN IF(newscore1 <> BLANK(),'Table'[Score2] &"/" & newscore1)

 

I think this is the result you want:

vyadongfmsft_0-1663724800531.png

 

Best regards,

Yadong Fang

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

Thank you very much, it is very closed. I provided two screenshots. If i don't select the month and type the result should be 10/93 (1+4+3+2)/43+50. Similarly if I select the month it should be 9 / 50. Regards.25.jpg

amitchandak
Super User
Super User

@IF , Create a measure like

 

Divide(Sum(Table[Score1]), Sum(Table[Score2]))

 

And in visual-only use name and month, do use type 

 

else try

 

calculate(Divide(Sum(Table[Score1]), Sum(Table[Score2])) , filter(Allselected(Table), Table[name] = max(Table[name])  && Table[Month] = max(Table[Month])  ) )

Hi,

I tried both options but doesn't work. I want to highlight again that I am using "type" slicer and the data is not normal. Thanks

25.jpg

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.