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
NickProp28
Post Partisan
Post Partisan

Convert C to DAX

Dear Community,

 

This is part of my dataset import from Excel

CountryNo of packageMonth
US1January
SG2January
US7February
US4January

 

This is the total sum of No packages with month.

NickProp28_0-1597135959167.png

I have total packages of this items and would like to have a DAX measure to determine how many pallet size to get on it. 

I have 10size pallet and 20size pallet. 
For example, January I have 247items, so calculate it will require twelve 20size pallet and one 10 size pallet.  (247/20 = 12.35, remainder will go into the 10size pallet.) 

 

In C language, 
if totalitem > 20, 

   Num20 = totalitem/20 
   Remain1 = totalitem % 20
}

if Remain1 > 0

{

   Num10 = Remain1/10

   Remain2 = Remain1 % 10
}

 

And my expected outcome will like 

Country MonthsNo of PackagesMeasure
USJanuary24712 20s pallet and 1 10s pallet.

I appreciate you taking the time to answer my question. I am sure you are very busy and thank you for taking the time to personally respond to me. Thanks again.

 

 

3 ACCEPTED SOLUTIONS
Fowmy
Super User
Super User

@NickProp28

Try these two measurements for 20 and 10

20 Plt = 

INT(DIVIDE(SUM(TABLE[NO OF PACKAGES]),20))

10 Plt = 

ROUNDUP(MOD(sum(TABLE[NO OF PACKAGES]),20),-1)/10

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click the Thumbs-Up icon on the right if you like this answer 🙂

YoutubeLinkedin

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

v-alq-msft
Community Support
Community Support

Hello, @NickProp28

According to your description, I created data to reproduce your scenario. The pbix file is attached at the end.

Mesa:

a1.png

You can create a measure like the following.

Result = 
var _value = SUM('Table'[No of Packages])
var _num20 = INT(DIVIDE(_value,20))
var _remain1 = MOD(_value,20)
var _num10 = ROUNDUP(DIVIDE(_remain1,10),0)
var _remain2 = MOD(_remain1,10)
return
IF(
    _value>20,
    IF(
        _remain1>0,
        _num20&" 20s pallet and "&_num10&" 10s pallet",
        _num20&" 20s pallet"
    ),
    INT(DIVIDE(_value,10))&" 10s pallet"
)

Result:

a2.png

Best regards

Allan

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

View solution in original post

@NickProp28

It rounds one decimal place to the left of the decimal point.

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, Linkedin

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

View solution in original post

7 REPLIES 7
v-alq-msft
Community Support
Community Support

Hello, @NickProp28

According to your description, I created data to reproduce your scenario. The pbix file is attached at the end.

Mesa:

a1.png

You can create a measure like the following.

Result = 
var _value = SUM('Table'[No of Packages])
var _num20 = INT(DIVIDE(_value,20))
var _remain1 = MOD(_value,20)
var _num10 = ROUNDUP(DIVIDE(_remain1,10),0)
var _remain2 = MOD(_remain1,10)
return
IF(
    _value>20,
    IF(
        _remain1>0,
        _num20&" 20s pallet and "&_num10&" 10s pallet",
        _num20&" 20s pallet"
    ),
    INT(DIVIDE(_value,10))&" 10s pallet"
)

Result:

a2.png

Best regards

Allan

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

Dear @Fowmy @v-alq-msft ,

Really appreciate yous guys solution. Two of it works perfectly for me. Thanks!

Dear @Fowmy .

10 Plt = ROUNDUP(MOD(sum(Data[NO OF PACKAGES]),20),-1)/10 . May I know why there have -1 in this formula. Thank you for providing me with advice.

@NickProp28

It rounds one decimal place to the left of the decimal point.

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click on the Thumbs-Up icon on the right if you like this reply 🙂

YouTube, Linkedin

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

Dear @Fowmy ,

 

Thank you. 

Fowmy
Super User
Super User

@NickProp28

Try these two measurements for 20 and 10

20 Plt = 

INT(DIVIDE(SUM(TABLE[NO OF PACKAGES]),20))

10 Plt = 

ROUNDUP(MOD(sum(TABLE[NO OF PACKAGES]),20),-1)/10

________________________

Did I answer your question? Mark this post as a solution, this will help others!.

Click the Thumbs-Up icon on the right if you like this answer 🙂

YoutubeLinkedin

Did I answer your question? Mark my post as a solution! and hit thumbs up


Subscribe and learn Power BI from these videos

Website LinkedIn PBI User Group

amitchandak
Super User
Super User

Dear @amitchandak,

 

Thanks for your prompt response,

NickProp28_0-1597138178707.png

I would like to create a measure based on no of packages, but im getting problem on it.

NickProp28_1-1597138296470.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.